Commit fc79c737 authored by con's avatar con
Browse files

Add last edit position to navigation history.

Task:     240811
parent f84c6514
...@@ -719,8 +719,8 @@ bool EditorManager::closeEditors(const QList<IEditor*> editorsToClose, bool askA ...@@ -719,8 +719,8 @@ bool EditorManager::closeEditors(const QList<IEditor*> editorsToClose, bool askA
} }
} }
emit editorsClosed(acceptedEditors); emit editorsClosed(acceptedEditors);
foreach (IEditor *editor, acceptedEditors) { foreach (IEditor *editor, acceptedEditors) {
delete editor; delete editor;
} }
...@@ -1358,7 +1358,7 @@ QList<IEditor*> EditorManager::editorHistory() const ...@@ -1358,7 +1358,7 @@ QList<IEditor*> EditorManager::editorHistory() const
return m_d->m_editorHistory; return m_d->m_editorHistory;
} }
void EditorManager::addCurrentPositionToNavigationHistory(bool compress) void EditorManager::addCurrentPositionToNavigationHistory(const QByteArray &saveState)
{ {
IEditor *editor = currentEditor(); IEditor *editor = currentEditor();
if (!editor) if (!editor)
...@@ -1367,7 +1367,15 @@ void EditorManager::addCurrentPositionToNavigationHistory(bool compress) ...@@ -1367,7 +1367,15 @@ void EditorManager::addCurrentPositionToNavigationHistory(bool compress)
return; return;
QString fileName = editor->file()->fileName(); QString fileName = editor->file()->fileName();
QByteArray state = editor->saveState(); bool compress;
QByteArray state;
if (saveState.isNull()) {
state = editor->saveState();
compress = false;
} else {
state = saveState;
compress = true;
}
// cut existing // cut existing
int firstIndexToRemove; int firstIndexToRemove;
if (compress && m_d->currentNavigationHistoryPosition > 0) { if (compress && m_d->currentNavigationHistoryPosition > 0) {
......
...@@ -132,7 +132,7 @@ public: ...@@ -132,7 +132,7 @@ public:
QList<IEditor*> editorsForFiles(QList<IFile*> files) const; QList<IEditor*> editorsForFiles(QList<IFile*> files) const;
//QList<EditorGroup *> editorGroups() const; //QList<EditorGroup *> editorGroups() const;
QList<IEditor*> editorHistory() const; QList<IEditor*> editorHistory() const;
void addCurrentPositionToNavigationHistory(bool compress = false); void addCurrentPositionToNavigationHistory(const QByteArray &saveState = QByteArray());
bool saveEditor(IEditor *editor); bool saveEditor(IEditor *editor);
......
...@@ -564,8 +564,6 @@ Core::IFile *BaseTextEditor::file() ...@@ -564,8 +564,6 @@ Core::IFile *BaseTextEditor::file()
void BaseTextEditor::editorContentsChange(int position, int charsRemoved, int charsAdded) void BaseTextEditor::editorContentsChange(int position, int charsRemoved, int charsAdded)
{ {
d->m_contentsChanged = true; d->m_contentsChanged = true;
// add last edit position to history
Core::EditorManager::instance()->addCurrentPositionToNavigationHistory(true);
// Keep the line numbers and the block information for the text marks updated // Keep the line numbers and the block information for the text marks updated
if (charsRemoved != 0) { if (charsRemoved != 0) {
...@@ -750,7 +748,6 @@ void BaseTextEditor::cleanWhitespace() ...@@ -750,7 +748,6 @@ void BaseTextEditor::cleanWhitespace()
void BaseTextEditor::keyPressEvent(QKeyEvent *e) void BaseTextEditor::keyPressEvent(QKeyEvent *e)
{ {
d->clearVisibleCollapsedBlock(); d->clearVisibleCollapsedBlock();
QKeyEvent *original_e = e; QKeyEvent *original_e = e;
...@@ -764,8 +761,6 @@ void BaseTextEditor::keyPressEvent(QKeyEvent *e) ...@@ -764,8 +761,6 @@ void BaseTextEditor::keyPressEvent(QKeyEvent *e)
return; return;
} }
d->m_contentsChanged = false;
bool ro = isReadOnly(); bool ro = isReadOnly();
if (d->m_inBlockSelectionMode) { if (d->m_inBlockSelectionMode) {
...@@ -964,7 +959,7 @@ void BaseTextEditor::setTextCursor(const QTextCursor &cursor) ...@@ -964,7 +959,7 @@ void BaseTextEditor::setTextCursor(const QTextCursor &cursor)
slotSelectionChanged(); slotSelectionChanged();
} }
void BaseTextEditor::gotoLine(int line, int column) void BaseTextEditor::gotoLine(int line, int column, bool saveNewPosition)
{ {
const int blockNumber = line - 1; const int blockNumber = line - 1;
const QTextBlock &block = document()->findBlockByNumber(blockNumber); const QTextBlock &block = document()->findBlockByNumber(blockNumber);
...@@ -982,6 +977,8 @@ void BaseTextEditor::gotoLine(int line, int column) ...@@ -982,6 +977,8 @@ void BaseTextEditor::gotoLine(int line, int column)
setTextCursor(cursor); setTextCursor(cursor);
centerCursor(); centerCursor();
} }
if (saveNewPosition)
saveCurrentCursorPositionForNavigation();
} }
int BaseTextEditor::position(ITextEditor::PositionOperation posOp, int at) const int BaseTextEditor::position(ITextEditor::PositionOperation posOp, int at) const
...@@ -1034,6 +1031,7 @@ QChar BaseTextEditor::characterAt(int pos) const ...@@ -1034,6 +1031,7 @@ QChar BaseTextEditor::characterAt(int pos) const
bool BaseTextEditor::event(QEvent *e) bool BaseTextEditor::event(QEvent *e)
{ {
d->m_contentsChanged = false;
switch (e->type()) { switch (e->type()) {
case QEvent::ShortcutOverride: case QEvent::ShortcutOverride:
e->ignore(); // we are a really nice citizen e->ignore(); // we are a really nice citizen
...@@ -1117,7 +1115,7 @@ bool BaseTextEditor::restoreState(const QByteArray &state) ...@@ -1117,7 +1115,7 @@ bool BaseTextEditor::restoreState(const QByteArray &state)
stream >> hval; stream >> hval;
stream >> lval; stream >> lval;
stream >> cval; stream >> cval;
gotoLine(lval, cval); gotoLine(lval, cval, false);
verticalScrollBar()->setValue(vval); verticalScrollBar()->setValue(vval);
horizontalScrollBar()->setValue(hval); horizontalScrollBar()->setValue(hval);
return true; return true;
...@@ -1251,6 +1249,7 @@ int BaseTextEditor::visibleWrapColumn() const ...@@ -1251,6 +1249,7 @@ int BaseTextEditor::visibleWrapColumn() const
BaseTextEditorPrivate::BaseTextEditorPrivate() BaseTextEditorPrivate::BaseTextEditorPrivate()
: :
m_contentsChanged(false), m_contentsChanged(false),
m_lastCursorChangeWasInteresting(false),
m_document(new BaseTextDocument()), m_document(new BaseTextDocument()),
m_parenthesesMatchingEnabled(false), m_parenthesesMatchingEnabled(false),
m_extraArea(0), m_extraArea(0),
...@@ -1436,6 +1435,7 @@ QRectF TextEditDocumentLayout::blockBoundingRect(const QTextBlock &block) const ...@@ -1436,6 +1435,7 @@ QRectF TextEditDocumentLayout::blockBoundingRect(const QTextBlock &block) const
bool BaseTextEditor::viewportEvent(QEvent *event) bool BaseTextEditor::viewportEvent(QEvent *event)
{ {
d->m_contentsChanged = false;
if (event->type() == QEvent::ContextMenu) { if (event->type() == QEvent::ContextMenu) {
const QContextMenuEvent *ce = static_cast<QContextMenuEvent*>(event); const QContextMenuEvent *ce = static_cast<QContextMenuEvent*>(event);
if (ce->reason() == QContextMenuEvent::Mouse && !textCursor().hasSelection()) if (ce->reason() == QContextMenuEvent::Mouse && !textCursor().hasSelection())
...@@ -2322,8 +2322,20 @@ void BaseTextEditor::slotUpdateRequest(const QRect &r, int dy) ...@@ -2322,8 +2322,20 @@ void BaseTextEditor::slotUpdateRequest(const QRect &r, int dy)
slotUpdateExtraAreaWidth(); slotUpdateExtraAreaWidth();
} }
void BaseTextEditor::saveCurrentCursorPositionForNavigation()
{
d->m_lastCursorChangeWasInteresting = true;
d->m_tempState = saveState();
}
void BaseTextEditor::slotCursorPositionChanged() void BaseTextEditor::slotCursorPositionChanged()
{ {
if (!d->m_contentsChanged && d->m_lastCursorChangeWasInteresting) {
Core::EditorManager::instance()->addCurrentPositionToNavigationHistory(d->m_tempState);
d->m_lastCursorChangeWasInteresting = false;
} else if (d->m_contentsChanged) {
saveCurrentCursorPositionForNavigation();
}
QList<QTextEdit::ExtraSelection> extraSelections; QList<QTextEdit::ExtraSelection> extraSelections;
setExtraSelections(ParenthesesMatchingSelection, extraSelections); // clear setExtraSelections(ParenthesesMatchingSelection, extraSelections); // clear
if (d->m_parenthesesMatchingEnabled) if (d->m_parenthesesMatchingEnabled)
......
...@@ -241,7 +241,7 @@ public: ...@@ -241,7 +241,7 @@ public:
// ITextEditor // ITextEditor
void gotoLine(int line, int column = 0); void gotoLine(int line, int column = 0, bool saveNewPosition = true);
int position( int position(
ITextEditor::PositionOperation posOp = ITextEditor::Current ITextEditor::PositionOperation posOp = ITextEditor::Current
...@@ -454,6 +454,7 @@ private: ...@@ -454,6 +454,7 @@ private:
void handleHomeKey(bool anchor); void handleHomeKey(bool anchor);
void handleBackspaceKey(); void handleBackspaceKey();
void moveLineUpDown(bool up); void moveLineUpDown(bool up);
void saveCurrentCursorPositionForNavigation();
void toggleBlockVisible(const QTextBlock &block); void toggleBlockVisible(const QTextBlock &block);
QRect collapseBox(const QTextBlock &block); QRect collapseBox(const QTextBlock &block);
...@@ -498,7 +499,7 @@ public: ...@@ -498,7 +499,7 @@ public:
int currentLine() const; int currentLine() const;
int currentColumn() const; int currentColumn() const;
inline void gotoLine(int line, int column = 0) { e->gotoLine(line, column); } void gotoLine(int line, int column = 0) { e->gotoLine(line, column); }
inline int position( inline int position(
ITextEditor::PositionOperation posOp = ITextEditor::Current ITextEditor::PositionOperation posOp = ITextEditor::Current
......
...@@ -140,6 +140,7 @@ public: ...@@ -140,6 +140,7 @@ public:
BaseTextEditor *q; BaseTextEditor *q;
bool m_contentsChanged; bool m_contentsChanged;
bool m_lastCursorChangeWasInteresting;
QList<QTextEdit::ExtraSelection> m_syntaxHighlighterSelections; QList<QTextEdit::ExtraSelection> m_syntaxHighlighterSelections;
QTextEdit::ExtraSelection m_lineSelection; QTextEdit::ExtraSelection m_lineSelection;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment