Skip to content

Commit

Permalink
Fix windows codeTemplate still incorrect position bug when re-open a …
Browse files Browse the repository at this point in the history
…document
  • Loading branch information
jie-meng committed Apr 17, 2018
1 parent 9159f21 commit 446564a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/gui/aboutdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void AboutDialog::init()

void AboutDialog::initGui()
{
plabel_version_ = new QLabel(tr("Version: 1.10.2"));
plabel_version_ = new QLabel(tr("Version: 1.10.3"));
plabel_email_ = new QLabel(tr("Email: [email protected]"));
plabel_github_ = createLinkLabel("Lunar on Github", "https://github.com/jie-meng/Lunar");
plabel_wiki_ = createLinkLabel("Lunar Wiki", "https://github.com/jie-meng/Lunar/wiki");
Expand Down
7 changes: 2 additions & 5 deletions src/gui/docview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -955,11 +955,8 @@ void DocView::codeTemplate()
int end = 0;
if (Extension::getInstance().templateFileInfo(it->second, index - (end_pos - start_pos), template_content, begin, end))
{
int offset = 0;
if (platformInfo() == kPlatformWindows) {
//On windows start_pos is not same as Unix, might caused by end of line '\r\n' not '\n'.
offset = line;
}
//On windows start_pos is not same as Unix, might caused by end of line '\r\n' not '\n'.
int offset = platformInfo() == kPlatformWindows ? line : 0;

ptext_edit_->replaceSelectedText(StdStringToQString(template_content));
ptext_edit_->setSelection(0, start_pos - offset + begin, 0, start_pos - offset + end);
Expand Down
8 changes: 6 additions & 2 deletions src/lunarcommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@ QString qtReadFile(const QString& filename, const char* codec)
QTextStream in(&f);
in.setCodec(codec);
QString str;

//On windows start_pos is not same as Unix, might caused by end of line '\r\n' not '\n'.
QString lineSep = platformInfo() == kPlatformWindows ? "\r\n" : "\n";

while(!in.atEnd())
str.append(in.readLine() + "\n");
str.append(in.readLine() + lineSep);

return str;
}
Expand Down Expand Up @@ -276,7 +280,7 @@ void LunarGlobal::readCfg(bool read_all)
extension_func_is_legal_file_ = text_cfg.getValue("Extension.Func.IsLegalFile", "isLegalFile");
extension_func_find_files_ = text_cfg.getValue("Extension.Func.FindFiles", "findFiles");

if (read_all)
if (read_all)
{
//These files can be changed in App
string font_type = text_cfg.getValue("Font.Type", string("Monaco"));
Expand Down

0 comments on commit 446564a

Please sign in to comment.