diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index d4e496c22b5bfcda80130fb32784f75363aebe7e..45c8580fd6e8d383c0c30da1e3407b03b32236b1 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -739,6 +739,89 @@ void BaseTextEditor::gotoBlockEndWithSelection() } } + +void BaseTextEditor::gotoLineStart() +{ + handleHomeKey(false); +} + +void BaseTextEditor::gotoLineStartWithSelection() +{ + handleHomeKey(true); +} + +void BaseTextEditor::gotoLineEnd() +{ + moveCursor(QTextCursor::EndOfLine); +} + +void BaseTextEditor::gotoLineEndWithSelection() +{ + moveCursor(QTextCursor::EndOfLine, QTextCursor::KeepAnchor); +} + +void BaseTextEditor::gotoNextLine() +{ + moveCursor(QTextCursor::NextRow); +} + +void BaseTextEditor::gotoNextLineWithSelection() +{ + moveCursor(QTextCursor::NextRow, QTextCursor::KeepAnchor); +} + +void BaseTextEditor::gotoPreviousLine() +{ + moveCursor(QTextCursor::PreviousRow); +} + +void BaseTextEditor::gotoPreviousLineWithSelection() +{ + moveCursor(QTextCursor::PreviousRow, QTextCursor::KeepAnchor); +} + +void BaseTextEditor::gotoPreviousCharacter() +{ + moveCursor(QTextCursor::PreviousCharacter); +} + +void BaseTextEditor::gotoPreviousCharacterWithSelection() +{ + moveCursor(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor); +} + +void BaseTextEditor::gotoNextCharacter() +{ + moveCursor(QTextCursor::NextCharacter); +} + +void BaseTextEditor::gotoNextCharacterWithSelection() +{ + moveCursor(QTextCursor::NextCharacter, QTextCursor::KeepAnchor); +} + +void BaseTextEditor::gotoPreviousWord() +{ + moveCursor(QTextCursor::PreviousWord); +} + +void BaseTextEditor::gotoPreviousWordWithSelection() +{ + moveCursor(QTextCursor::PreviousWord, QTextCursor::KeepAnchor); +} + +void BaseTextEditor::gotoNextWord() +{ + moveCursor(QTextCursor::NextWord); +} + +void BaseTextEditor::gotoNextWordWithSelection() +{ + moveCursor(QTextCursor::NextWord, QTextCursor::KeepAnchor); +} + + + static QTextCursor flippedCursor(const QTextCursor &cursor) { QTextCursor flipped = cursor; diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h index 67ef63858d6c2a1c4959dc46f9b729af56f0e2f8..8a3466735f74954bc02690478b8b5463d602654f 100644 --- a/src/plugins/texteditor/basetexteditor.h +++ b/src/plugins/texteditor/basetexteditor.h @@ -231,6 +231,23 @@ public slots: void gotoBlockStartWithSelection(); void gotoBlockEndWithSelection(); + void gotoLineStart(); + void gotoLineStartWithSelection(); + void gotoLineEnd(); + void gotoLineEndWithSelection(); + void gotoNextLine(); + void gotoNextLineWithSelection(); + void gotoPreviousLine(); + void gotoPreviousLineWithSelection(); + void gotoPreviousCharacter(); + void gotoPreviousCharacterWithSelection(); + void gotoNextCharacter(); + void gotoNextCharacterWithSelection(); + void gotoPreviousWord(); + void gotoPreviousWordWithSelection(); + void gotoNextWord(); + void gotoNextWordWithSelection(); + void selectBlockUp(); void selectBlockDown(); diff --git a/src/plugins/texteditor/texteditoractionhandler.cpp b/src/plugins/texteditor/texteditoractionhandler.cpp index d08912fe9d723408775cae710d107f34354ccb53..81ab291ab9d7d4293f1d298e03d74663498062ce 100644 --- a/src/plugins/texteditor/texteditoractionhandler.cpp +++ b/src/plugins/texteditor/texteditoractionhandler.cpp @@ -292,6 +292,59 @@ void TextEditorActionHandler::createActions() command = am->registerAction(m_joinLinesAction, Constants::JOIN_LINES, m_contextId); command->setDefaultKeySequence(QKeySequence(tr("Ctrl+J"))); connect(m_joinLinesAction, SIGNAL(triggered()), this, SLOT(joinLines())); + + + QAction *a = 0; + a = new QAction(tr("Goto Line Start"), this); + command = am->registerAction(a, Constants::GOTO_LINE_START, m_contextId); + connect(a, SIGNAL(triggered()), this, SLOT(gotoLineStart())); + a = new QAction(tr("Goto Line End"), this); + command = am->registerAction(a, Constants::GOTO_LINE_END, m_contextId); + connect(a, SIGNAL(triggered()), this, SLOT(gotoLineEnd())); + a = new QAction(tr("Goto Next Line"), this); + command = am->registerAction(a, Constants::GOTO_NEXT_LINE, m_contextId); + connect(a, SIGNAL(triggered()), this, SLOT(gotoNextLine())); + a = new QAction(tr("Goto Previous Line"), this); + command = am->registerAction(a, Constants::GOTO_PREVIOUS_LINE, m_contextId); + connect(a, SIGNAL(triggered()), this, SLOT(gotoPreviousLine())); + a = new QAction(tr("Goto Previous Character"), this); + command = am->registerAction(a, Constants::GOTO_PREVIOUS_CHARACTER, m_contextId); + connect(a, SIGNAL(triggered()), this, SLOT(gotoPreviousCharacter())); + a = new QAction(tr("Goto Next Character"), this); + command = am->registerAction(a, Constants::GOTO_NEXT_CHARACTER, m_contextId); + connect(a, SIGNAL(triggered()), this, SLOT(gotoNextCharacter())); + a = new QAction(tr("Goto Previous Word"), this); + command = am->registerAction(a, Constants::GOTO_PREVIOUS_WORD, m_contextId); + connect(a, SIGNAL(triggered()), this, SLOT(gotoPreviousWord())); + a = new QAction(tr("Goto Next Word"), this); + command = am->registerAction(a, Constants::GOTO_NEXT_WORD, m_contextId); + connect(a, SIGNAL(triggered()), this, SLOT(gotoNextWord())); + + a = new QAction(tr("Goto Line Start With Selection"), this); + command = am->registerAction(a, Constants::GOTO_LINE_START_WITH_SELECTION, m_contextId); + connect(a, SIGNAL(triggered()), this, SLOT(gotoLineStartWithSelection())); + a = new QAction(tr("Goto Line End With Selection"), this); + command = am->registerAction(a, Constants::GOTO_LINE_END_WITH_SELECTION, m_contextId); + connect(a, SIGNAL(triggered()), this, SLOT(gotoLineEndWithSelection())); + a = new QAction(tr("Goto Next Line With Selection"), this); + command = am->registerAction(a, Constants::GOTO_NEXT_LINE_WITH_SELECTION, m_contextId); + connect(a, SIGNAL(triggered()), this, SLOT(gotoNextLineWithSelection())); + a = new QAction(tr("Goto Previous Line With Selection"), this); + command = am->registerAction(a, Constants::GOTO_PREVIOUS_LINE_WITH_SELECTION, m_contextId); + connect(a, SIGNAL(triggered()), this, SLOT(gotoPreviousLineWithSelection())); + a = new QAction(tr("Goto Previous Character With Selection"), this); + command = am->registerAction(a, Constants::GOTO_PREVIOUS_CHARACTER_WITH_SELECTION, m_contextId); + connect(a, SIGNAL(triggered()), this, SLOT(gotoPreviousCharacterWithSelection())); + a = new QAction(tr("Goto Next Character With Selection"), this); + command = am->registerAction(a, Constants::GOTO_NEXT_CHARACTER_WITH_SELECTION, m_contextId); + connect(a, SIGNAL(triggered()), this, SLOT(gotoNextCharacterWithSelection())); + a = new QAction(tr("Goto Previous Word With Selection"), this); + command = am->registerAction(a, Constants::GOTO_PREVIOUS_WORD_WITH_SELECTION, m_contextId); + connect(a, SIGNAL(triggered()), this, SLOT(gotoPreviousWordWithSelection())); + a = new QAction(tr("Goto Next Word With Selection"), this); + command = am->registerAction(a, Constants::GOTO_NEXT_WORD_WITH_SELECTION, m_contextId); + connect(a, SIGNAL(triggered()), this, SLOT(gotoNextWordWithSelection())); + } bool TextEditorActionHandler::supportsAction(const QString & /*id */) const @@ -455,6 +508,24 @@ FUNCTION(copyLineUp) FUNCTION(copyLineDown) FUNCTION(joinLines) +FUNCTION(gotoLineStart) +FUNCTION(gotoLineStartWithSelection) +FUNCTION(gotoLineEnd) +FUNCTION(gotoLineEndWithSelection) +FUNCTION(gotoNextLine) +FUNCTION(gotoNextLineWithSelection) +FUNCTION(gotoPreviousLine) +FUNCTION(gotoPreviousLineWithSelection) +FUNCTION(gotoPreviousCharacter) +FUNCTION(gotoPreviousCharacterWithSelection) +FUNCTION(gotoNextCharacter) +FUNCTION(gotoNextCharacterWithSelection) +FUNCTION(gotoPreviousWord) +FUNCTION(gotoPreviousWordWithSelection) +FUNCTION(gotoNextWord) +FUNCTION(gotoNextWordWithSelection) + + void TextEditorActionHandler::updateCurrentEditor(Core::IEditor *editor) { m_currentEditor = 0; diff --git a/src/plugins/texteditor/texteditoractionhandler.h b/src/plugins/texteditor/texteditoractionhandler.h index 2b8b7a039c036bf6ea3fa22ec49d52549caa81b9..667ce575086702d2c7eacd88b8bd16f58888a3bc 100644 --- a/src/plugins/texteditor/texteditoractionhandler.h +++ b/src/plugins/texteditor/texteditoractionhandler.h @@ -118,6 +118,24 @@ private slots: void joinLines(); void updateCurrentEditor(Core::IEditor *editor); + void gotoLineStart(); + void gotoLineStartWithSelection(); + void gotoLineEnd(); + void gotoLineEndWithSelection(); + void gotoNextLine(); + void gotoNextLineWithSelection(); + void gotoPreviousLine(); + void gotoPreviousLineWithSelection(); + void gotoPreviousCharacter(); + void gotoPreviousCharacterWithSelection(); + void gotoNextCharacter(); + void gotoNextCharacterWithSelection(); + void gotoPreviousWord(); + void gotoPreviousWordWithSelection(); + void gotoNextWord(); + void gotoNextWordWithSelection(); + + private: QAction *m_undoAction; QAction *m_redoAction; diff --git a/src/plugins/texteditor/texteditorconstants.h b/src/plugins/texteditor/texteditorconstants.h index 7fc41a9f888c53c233508d1b525242c649e86932..b0af1e7df0e9e3c61b434e9aef5b0fae84717e61 100644 --- a/src/plugins/texteditor/texteditorconstants.h +++ b/src/plugins/texteditor/texteditorconstants.h @@ -68,6 +68,22 @@ const char * const SELECT_ENCODING = "TextEditor.SelectEncoding"; const char * const REWRAP_PARAGRAPH = "TextEditor.RewrapParagraph"; const char * const GOTO_OPENING_PARENTHESIS = "TextEditor.GotoOpeningParenthesis"; const char * const GOTO_CLOSING_PARENTHESIS = "TextEditor.GotoClosingParenthesis"; +const char * const GOTO_LINE_START = "TextEditor.GotoLineStart"; +const char * const GOTO_LINE_END = "TextEditor.GotoLineEnd"; +const char * const GOTO_NEXT_LINE = "TextEditor.GotoNextLine"; +const char * const GOTO_PREVIOUS_LINE = "TextEditor.GotoPreviousLine"; +const char * const GOTO_PREVIOUS_CHARACTER = "TextEditor.GotoPreviousCharacter"; +const char * const GOTO_NEXT_CHARACTER = "TextEditor.GotoNextCharacter"; +const char * const GOTO_PREVIOUS_WORD = "TextEditor.GotoPreviousWord"; +const char * const GOTO_NEXT_WORD = "TextEditor.GotoNextWord"; +const char * const GOTO_LINE_START_WITH_SELECTION = "TextEditor.GotoLineStartWithSelection"; +const char * const GOTO_LINE_END_WITH_SELECTION = "TextEditor.GotoLineEndWithSelection"; +const char * const GOTO_NEXT_LINE_WITH_SELECTION = "TextEditor.GotoNextLineWithSelection"; +const char * const GOTO_PREVIOUS_LINE_WITH_SELECTION = "TextEditor.GotoPreviousLineWithSelection"; +const char * const GOTO_PREVIOUS_CHARACTER_WITH_SELECTION = "TextEditor.GotoPreviousCharacterWithSelection"; +const char * const GOTO_NEXT_CHARACTER_WITH_SELECTION = "TextEditor.GotoNextCharacterWithSelection"; +const char * const GOTO_PREVIOUS_WORD_WITH_SELECTION = "TextEditor.GotoPreviousWordWithSelection"; +const char * const GOTO_NEXT_WORD_WITH_SELECTION = "TextEditor.GotoNextWordWithSelection"; const char * const C_TEXTEDITOR_MIMETYPE_TEXT = "text/plain"; const char * const C_TEXTEDITOR_MIMETYPE_XML = "application/xml";