diff --git a/src/view/kateview.h b/src/view/kateview.h --- a/src/view/kateview.h +++ b/src/view/kateview.h @@ -445,35 +445,80 @@ void goToPreviousEditingPosition(); /** - * Sets the cursor to the next editing position in this document + * Sets the cursor to the next editing position in this document. */ void goToNextEditingPosition(); /** - Uppercases selected text, or an alphabetic character next to the cursor. - */ + * Uppercases selected text, or an alphabetic character next to the cursor. + */ void uppercase(); + /** - Lowercases selected text, or an alphabetic character next to the cursor. - */ + * Lowercases selected text, or an alphabetic character next to the cursor. + */ void lowercase(); + /** - Capitalizes the selection (makes each word start with an uppercase) or - the word under the cursor. - */ + * Capitalizes the selection (makes each word start with an uppercase) or + * the word under the cursor. + */ void capitalize(); + /** - Joins lines touched by the selection - */ + * Joins lines touched by the selection. + */ void joinLines(); - // Note - the following functions simply forward to KateViewInternal + /** + * Performs a line break (insert a new line char) at current cursor position + * and indent the new line. + * + * Most work is done by @c KTextEditor::DocumentPrivate::newLine and + * @c KateAutoIndent::userTypedChar + * @see KTextEditor::DocumentPrivate::newLine, KateAutoIndent + */ void keyReturn(); + + /** + * Performs a line break (insert a new line char) at current cursor position + * but keep all leading non word char as indent for the new line. + */ void smartNewline(); + + /** + * Insert a tabulator char at current cursor position. + */ void backspace(); + + /** + * Remove the word left from the current cursor position including all leading + * space. + * @see KateViewInternal::wordPrev + */ void deleteWordLeft(); + + /** + * Remove the current selection. When nothing is selected the char right + * from the current cursor position is removed. + * @see KTextEditor::DocumentPrivate::del + */ void keyDelete(); + + /** + * When the char right from the current cursor position is a space is all + * space to the right removed. Otherwise is the word to the right including + * all trialling space removed. + * @see KateViewInternal::wordNext + */ void deleteWordRight(); + + /** + * Transpose the characters left and right from the current cursor position + * and move the cursor one position to the right. If the char right to the + * current cursor position is a new line char, nothing is done. + * @see KTextEditor::DocumentPrivate::transpose + */ void transpose(); void cursorLeft(); void shiftCursorLeft(); @@ -509,6 +554,9 @@ void shiftToMatchingBracket(); void toPrevModifiedLine(); void toNextModifiedLine(); + /** + * Insert a tabulator char at current cursor position. + */ void insertTab(); void gotoLine(); diff --git a/src/view/kateview.cpp b/src/view/kateview.cpp --- a/src/view/kateview.cpp +++ b/src/view/kateview.cpp @@ -2716,42 +2716,74 @@ void KTextEditor::ViewPrivate::keyReturn() { - m_viewInternal->doReturn(); + doc()->newLine(this); + m_viewInternal->iconBorder()->updateForCursorLineChange(); + m_viewInternal->updateView(); } void KTextEditor::ViewPrivate::smartNewline() { - m_viewInternal->doSmartNewline(); + const KTextEditor::Cursor cursor = cursorPosition(); + const int ln = cursor.line(); + Kate::TextLine line = doc()->kateTextLine(ln); + int col = qMin(cursor.column(), line->firstChar()); + if (col != -1) { + while (line->length() > col && + !(line->at(col).isLetterOrNumber() || line->at(col) == QLatin1Char('_')) && + col < cursor.column()) { + ++col; + } + } else { + col = line->length(); // stay indented + } + doc()->editStart(); + doc()->editWrapLine(ln, cursor.column()); + doc()->insertText(KTextEditor::Cursor(ln + 1, 0), line->string(0, col)); + doc()->editEnd(); + + m_viewInternal->updateView(); } void KTextEditor::ViewPrivate::backspace() { - m_viewInternal->doBackspace(); + doc()->backspace(this, cursorPosition()); } void KTextEditor::ViewPrivate::insertTab() { - m_viewInternal->doTabulator(); + doc()->insertTab(this, cursorPosition()); } void KTextEditor::ViewPrivate::deleteWordLeft() { - m_viewInternal->doDeletePrevWord(); + doc()->editStart(); + m_viewInternal->wordPrev(true); + KTextEditor::Range selection = selectionRange(); + removeSelectedText(); + doc()->editEnd(); + m_viewInternal->tagRange(selection, true); + m_viewInternal->updateDirty(); } void KTextEditor::ViewPrivate::keyDelete() { - m_viewInternal->doDelete(); + doc()->del(this, cursorPosition()); } void KTextEditor::ViewPrivate::deleteWordRight() { - m_viewInternal->doDeleteNextWord(); + doc()->editStart(); + m_viewInternal->wordNext(true); + KTextEditor::Range selection = selectionRange(); + removeSelectedText(); + doc()->editEnd(); + m_viewInternal->tagRange(selection, true); + m_viewInternal->updateDirty(); } void KTextEditor::ViewPrivate::transpose() { - m_viewInternal->doTranspose(); + doc()->transpose(cursorPosition()); } void KTextEditor::ViewPrivate::cursorLeft() diff --git a/src/view/kateviewinternal.h b/src/view/kateviewinternal.h --- a/src/view/kateviewinternal.h +++ b/src/view/kateviewinternal.h @@ -127,8 +127,6 @@ void updateView(bool changed = false, int viewLinesScrolled = 0); private: - // Actually performs the updating, but doesn't call update(). - void doUpdateView(bool changed = false, int viewLinesScrolled = 0); void makeVisible(const KTextEditor::Cursor &c, int endCol, bool force = false, bool center = false, bool calledExternally = false); public: @@ -172,15 +170,6 @@ void viewSelectionChanged(); public: - void doReturn(); - void doSmartNewline(); - void doDelete(); - void doBackspace(); - void doTabulator(); - void doTranspose(); - void doDeletePrevWord(); - void doDeleteNextWord(); - void cursorPrevChar(bool sel = false); void cursorNextChar(bool sel = false); void wordPrev(bool sel = false); diff --git a/src/view/kateviewinternal.cpp b/src/view/kateviewinternal.cpp --- a/src/view/kateviewinternal.cpp +++ b/src/view/kateviewinternal.cpp @@ -607,15 +607,6 @@ // If changed is true, the lines that have been set dirty have been updated. void KateViewInternal::updateView(bool changed, int viewLinesScrolled) -{ - doUpdateView(changed, viewLinesScrolled); - - if (changed) { - updateDirty(); - } -} - -void KateViewInternal::doUpdateView(bool changed, int viewLinesScrolled) { if (!isVisible() && !viewLinesScrolled && !changed) { return; //When this view is not visible, don't do anything @@ -692,6 +683,10 @@ } m_dummy->setVisible(visible_dummy); + + if (changed) { + updateDirty(); + } } /** @@ -877,76 +872,6 @@ return c; } -void KateViewInternal::doReturn() -{ - doc()->newLine(m_view); - m_leftBorder->updateForCursorLineChange(); - updateView(); -} - -void KateViewInternal::doSmartNewline() -{ - int ln = m_cursor.line(); - Kate::TextLine line = doc()->kateTextLine(ln); - int col = qMin(m_cursor.column(), line->firstChar()); - if (col != -1) { - while (line->length() > col && - !(line->at(col).isLetterOrNumber() || line->at(col) == QLatin1Char('_')) && - col < m_cursor.column()) { - ++col; - } - } else { - col = line->length(); // stay indented - } - doc()->editStart(); - doc()->editWrapLine(ln, m_cursor.column()); - doc()->insertText(KTextEditor::Cursor(ln + 1, 0), line->string(0, col)); - doc()->editEnd(); - - updateView(); -} - -void KateViewInternal::doDelete() -{ - doc()->del(m_view, m_cursor); -} - -void KateViewInternal::doBackspace() -{ - doc()->backspace(m_view, m_cursor); -} - -void KateViewInternal::doTabulator() -{ - doc()->insertTab(m_view, m_cursor); -} - -void KateViewInternal::doTranspose() -{ - doc()->transpose(m_cursor); -} - -void KateViewInternal::doDeletePrevWord() -{ - doc()->editStart(); - wordPrev(true); - KTextEditor::Range selection = m_view->selectionRange(); - m_view->removeSelectedText(); - doc()->editEnd(); - tagRange(selection, true); - updateDirty(); -} - -void KateViewInternal::doDeleteNextWord() -{ - doc()->editStart(); - wordNext(true); - KTextEditor::Range selection = m_view->selectionRange(); - m_view->removeSelectedText(); - doc()->editEnd(); - tagRange(selection, true); - updateDirty(); -} class CalculatingCursor { @@ -2460,7 +2385,7 @@ } if ((key == Qt::Key_Return) || (key == Qt::Key_Enter) || (key == Qt::SHIFT + Qt::Key_Return) || (key == Qt::SHIFT + Qt::Key_Enter)) { - doReturn(); + m_view->keyReturn(); e->accept(); return; }