- fix: error when delete contents in column mode on lines that has wide-chars

- fix: error when create folder in files view
This commit is contained in:
Roy Qu 2022-03-15 15:34:34 +08:00
parent 469c5f21d3
commit 021880b746
4 changed files with 303 additions and 295 deletions

View File

@ -21,6 +21,8 @@ Red Panda C++ Version 1.0.0
- fix: correctly reset caret when redo cut with no selection - fix: correctly reset caret when redo cut with no selection
- enhancement: close editor when middle button clicked on it's title tab - enhancement: close editor when middle button clicked on it's title tab
- fix: error when insert text in column mode - fix: error when insert text in column mode
- fix: error when delete contents in column mode on lines that has wide-chars
- fix: error when create folder in files view
Red Panda C++ Version 0.14.5 Red Panda C++ Version 0.14.5
- fix: the "gnu c++ 20" option in compiler set options is wrong - fix: the "gnu c++ 20" option in compiler set options is wrong

File diff suppressed because it is too large Load Diff

View File

@ -3595,11 +3595,13 @@ void MainWindow::onFilesViewCreateFolder()
{ {
QModelIndex index = ui->treeFiles->currentIndex(); QModelIndex index = ui->treeFiles->currentIndex();
QDir dir; QDir dir;
if (index.isValid()) { if (index.isValid()
&& ui->treeFiles->selectionModel()->isSelected(index)) {
if (mFileSystemModel.isDir(index)) if (mFileSystemModel.isDir(index))
dir = QDir(mFileSystemModel.fileInfo(index).absoluteFilePath()); dir = QDir(mFileSystemModel.fileInfo(index).absoluteFilePath());
else else
dir = mFileSystemModel.fileInfo(index).absoluteDir(); dir = mFileSystemModel.fileInfo(index).absoluteDir();
ui->treeFiles->expand(index);
} else { } else {
dir = mFileSystemModel.rootDirectory(); dir = mFileSystemModel.rootDirectory();
} }
@ -3607,9 +3609,9 @@ void MainWindow::onFilesViewCreateFolder()
int count = 0; int count = 0;
while (dir.exists(folderName)) { while (dir.exists(folderName)) {
count++; count++;
folderName = tr("New Folder").arg(count); folderName = tr("New Folder %1").arg(count);
} }
mFileSystemModel.mkdir(index,folderName); dir.mkdir(dir.filePath(folderName));
} }
void MainWindow::onFilesViewRemoveFiles() void MainWindow::onFilesViewRemoveFiles()

View File

@ -5324,65 +5324,65 @@ int SynEdit::insertTextByNormalMode(const QString &Value)
return Result; return Result;
} }
int SynEdit::insertTextByColumnMode(const QString &Value, bool AddToUndoList) int SynEdit::insertTextByColumnMode(const QString &value, bool addToUndoList)
{ {
QString Str; QString str;
QString TempString; QString tempString;
int Start; int start;
int P; int p;
int Len; int len;
int InsertCol; int insertCol;
BufferCoord LineBreakPos; BufferCoord lineBreakPos;
int Result = 0; int result = 0;
// Insert string at current position // Insert string at current position
InsertCol = charToColumn(mCaretY,mCaretX); insertCol = charToColumn(mCaretY,mCaretX);
Start = 0; start = 0;
do { do {
P = GetEOL(Value,Start); p = GetEOL(value,start);
if (P != Start) { if (p != start) {
Str = Value.mid(Start,P-Start); str = value.mid(start,p-start);
// Move(Start^, Str[1], P - Start); // Move(Start^, Str[1], P - Start);
if (mCaretY > mLines->count()) { if (mCaretY > mLines->count()) {
Result++; result++;
TempString = QString(InsertCol - 1,' ') + Str; tempString = QString(insertCol - 1,' ') + str;
mLines->add(""); mLines->add("");
if (AddToUndoList) { if (addToUndoList) {
LineBreakPos.Line = mCaretY - 1; lineBreakPos.Line = mCaretY - 1;
LineBreakPos.Char = mLines->getString(mCaretY - 2).length() + 1; lineBreakPos.Char = mLines->getString(mCaretY - 2).length() + 1;
mUndoList->AddChange(SynChangeReason::crLineBreak, mUndoList->AddChange(SynChangeReason::crLineBreak,
LineBreakPos, lineBreakPos,
LineBreakPos, lineBreakPos,
"", SynSelectionMode::smNormal); "", SynSelectionMode::smNormal);
} }
} else { } else {
TempString = mLines->getString(mCaretY - 1); tempString = mLines->getString(mCaretY - 1);
Len = stringColumns(TempString,0); len = stringColumns(tempString,0);
if (Len < InsertCol) { if (len < insertCol) {
TempString = TempString + QString(InsertCol - Len - 1,' ') + Str; tempString = tempString + QString(insertCol - len - 1,' ') + str;
} else { } else {
int insertPos = charToColumn(TempString,InsertCol); int insertPos = columnToChar(mCaretY,insertCol);
TempString.insert(insertPos-1,Str); tempString.insert(insertPos-1,str);
} }
} }
properSetLine(mCaretY - 1, TempString); properSetLine(mCaretY - 1, tempString);
// Add undo change here from PasteFromClipboard // Add undo change here from PasteFromClipboard
if (AddToUndoList) { if (addToUndoList) {
mUndoList->AddChange(SynChangeReason::crPaste, BufferCoord{mCaretX, mCaretY}, mUndoList->AddChange(SynChangeReason::crPaste, BufferCoord{mCaretX, mCaretY},
BufferCoord{mCaretX + (P - Start), mCaretY}, "", mActiveSelectionMode); BufferCoord{mCaretX + (p - start), mCaretY}, "", mActiveSelectionMode);
} }
} }
if (P<Value.length() && ((Value[P]=='\r') || (Value[P]=='\n'))) { if (p<value.length() && ((value[p]=='\r') || (value[p]=='\n'))) {
P++; p++;
if (P<Value.length() && Value[P]=='\n') if (p<value.length() && value[p]=='\n')
P++; p++;
mCaretY++; mCaretY++;
mStatusChanges.setFlag(SynStatusChange::scCaretY); mStatusChanges.setFlag(SynStatusChange::scCaretY);
} }
Start = P; start = p;
} while (P<Value.length()); } while (p<value.length());
mCaretX+=Str.length(); mCaretX+=str.length();
mStatusChanges.setFlag(SynStatusChange::scCaretX); mStatusChanges.setFlag(SynStatusChange::scCaretX);
return Result; return result;
} }
int SynEdit::insertTextByLineMode(const QString &Value) int SynEdit::insertTextByLineMode(const QString &Value)