forked from qt-creator/qt-creator
Add last edit position to navigation history.
Task: 240811
This commit is contained in:
@@ -719,8 +719,8 @@ bool EditorManager::closeEditors(const QList<IEditor*> editorsToClose, bool askA
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
emit editorsClosed(acceptedEditors);
|
||||
|
||||
foreach (IEditor *editor, acceptedEditors) {
|
||||
delete editor;
|
||||
}
|
||||
@@ -1358,7 +1358,7 @@ QList<IEditor*> EditorManager::editorHistory() const
|
||||
return m_d->m_editorHistory;
|
||||
}
|
||||
|
||||
void EditorManager::addCurrentPositionToNavigationHistory(bool compress)
|
||||
void EditorManager::addCurrentPositionToNavigationHistory(const QByteArray &saveState)
|
||||
{
|
||||
IEditor *editor = currentEditor();
|
||||
if (!editor)
|
||||
@@ -1367,7 +1367,15 @@ void EditorManager::addCurrentPositionToNavigationHistory(bool compress)
|
||||
return;
|
||||
|
||||
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
|
||||
int firstIndexToRemove;
|
||||
if (compress && m_d->currentNavigationHistoryPosition > 0) {
|
||||
|
||||
@@ -132,7 +132,7 @@ public:
|
||||
QList<IEditor*> editorsForFiles(QList<IFile*> files) const;
|
||||
//QList<EditorGroup *> editorGroups() const;
|
||||
QList<IEditor*> editorHistory() const;
|
||||
void addCurrentPositionToNavigationHistory(bool compress = false);
|
||||
void addCurrentPositionToNavigationHistory(const QByteArray &saveState = QByteArray());
|
||||
|
||||
bool saveEditor(IEditor *editor);
|
||||
|
||||
|
||||
@@ -564,8 +564,6 @@ Core::IFile *BaseTextEditor::file()
|
||||
void BaseTextEditor::editorContentsChange(int position, int charsRemoved, int charsAdded)
|
||||
{
|
||||
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
|
||||
if (charsRemoved != 0) {
|
||||
@@ -750,7 +748,6 @@ void BaseTextEditor::cleanWhitespace()
|
||||
|
||||
void BaseTextEditor::keyPressEvent(QKeyEvent *e)
|
||||
{
|
||||
|
||||
d->clearVisibleCollapsedBlock();
|
||||
|
||||
QKeyEvent *original_e = e;
|
||||
@@ -764,8 +761,6 @@ void BaseTextEditor::keyPressEvent(QKeyEvent *e)
|
||||
return;
|
||||
}
|
||||
|
||||
d->m_contentsChanged = false;
|
||||
|
||||
bool ro = isReadOnly();
|
||||
|
||||
if (d->m_inBlockSelectionMode) {
|
||||
@@ -964,7 +959,7 @@ void BaseTextEditor::setTextCursor(const QTextCursor &cursor)
|
||||
slotSelectionChanged();
|
||||
}
|
||||
|
||||
void BaseTextEditor::gotoLine(int line, int column)
|
||||
void BaseTextEditor::gotoLine(int line, int column, bool saveNewPosition)
|
||||
{
|
||||
const int blockNumber = line - 1;
|
||||
const QTextBlock &block = document()->findBlockByNumber(blockNumber);
|
||||
@@ -982,6 +977,8 @@ void BaseTextEditor::gotoLine(int line, int column)
|
||||
setTextCursor(cursor);
|
||||
centerCursor();
|
||||
}
|
||||
if (saveNewPosition)
|
||||
saveCurrentCursorPositionForNavigation();
|
||||
}
|
||||
|
||||
int BaseTextEditor::position(ITextEditor::PositionOperation posOp, int at) const
|
||||
@@ -1034,6 +1031,7 @@ QChar BaseTextEditor::characterAt(int pos) const
|
||||
|
||||
bool BaseTextEditor::event(QEvent *e)
|
||||
{
|
||||
d->m_contentsChanged = false;
|
||||
switch (e->type()) {
|
||||
case QEvent::ShortcutOverride:
|
||||
e->ignore(); // we are a really nice citizen
|
||||
@@ -1117,7 +1115,7 @@ bool BaseTextEditor::restoreState(const QByteArray &state)
|
||||
stream >> hval;
|
||||
stream >> lval;
|
||||
stream >> cval;
|
||||
gotoLine(lval, cval);
|
||||
gotoLine(lval, cval, false);
|
||||
verticalScrollBar()->setValue(vval);
|
||||
horizontalScrollBar()->setValue(hval);
|
||||
return true;
|
||||
@@ -1251,6 +1249,7 @@ int BaseTextEditor::visibleWrapColumn() const
|
||||
BaseTextEditorPrivate::BaseTextEditorPrivate()
|
||||
:
|
||||
m_contentsChanged(false),
|
||||
m_lastCursorChangeWasInteresting(false),
|
||||
m_document(new BaseTextDocument()),
|
||||
m_parenthesesMatchingEnabled(false),
|
||||
m_extraArea(0),
|
||||
@@ -1436,6 +1435,7 @@ QRectF TextEditDocumentLayout::blockBoundingRect(const QTextBlock &block) const
|
||||
|
||||
bool BaseTextEditor::viewportEvent(QEvent *event)
|
||||
{
|
||||
d->m_contentsChanged = false;
|
||||
if (event->type() == QEvent::ContextMenu) {
|
||||
const QContextMenuEvent *ce = static_cast<QContextMenuEvent*>(event);
|
||||
if (ce->reason() == QContextMenuEvent::Mouse && !textCursor().hasSelection())
|
||||
@@ -2322,8 +2322,20 @@ void BaseTextEditor::slotUpdateRequest(const QRect &r, int dy)
|
||||
slotUpdateExtraAreaWidth();
|
||||
}
|
||||
|
||||
void BaseTextEditor::saveCurrentCursorPositionForNavigation()
|
||||
{
|
||||
d->m_lastCursorChangeWasInteresting = true;
|
||||
d->m_tempState = saveState();
|
||||
}
|
||||
|
||||
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;
|
||||
setExtraSelections(ParenthesesMatchingSelection, extraSelections); // clear
|
||||
if (d->m_parenthesesMatchingEnabled)
|
||||
|
||||
@@ -241,7 +241,7 @@ public:
|
||||
|
||||
// ITextEditor
|
||||
|
||||
void gotoLine(int line, int column = 0);
|
||||
void gotoLine(int line, int column = 0, bool saveNewPosition = true);
|
||||
|
||||
int position(
|
||||
ITextEditor::PositionOperation posOp = ITextEditor::Current
|
||||
@@ -454,6 +454,7 @@ private:
|
||||
void handleHomeKey(bool anchor);
|
||||
void handleBackspaceKey();
|
||||
void moveLineUpDown(bool up);
|
||||
void saveCurrentCursorPositionForNavigation();
|
||||
|
||||
void toggleBlockVisible(const QTextBlock &block);
|
||||
QRect collapseBox(const QTextBlock &block);
|
||||
@@ -498,7 +499,7 @@ public:
|
||||
|
||||
int currentLine() 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(
|
||||
ITextEditor::PositionOperation posOp = ITextEditor::Current
|
||||
|
||||
@@ -140,6 +140,7 @@ public:
|
||||
|
||||
BaseTextEditor *q;
|
||||
bool m_contentsChanged;
|
||||
bool m_lastCursorChangeWasInteresting;
|
||||
|
||||
QList<QTextEdit::ExtraSelection> m_syntaxHighlighterSelections;
|
||||
QTextEdit::ExtraSelection m_lineSelection;
|
||||
|
||||
Reference in New Issue
Block a user