I agree, this is annoying. The cursor should remain where it is when you press Ctrl+S. Some of us press Ctrl+S as a matter of course, as a good habit, and we do not when it makes logical sense to do so but when our fingers remember to do it :-)
--leuce
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
--- src/org/omegat/gui/editor/EditorController.java (revision 4070)
+++ src/org/omegat/gui/editor/EditorController.java (working copy)
@@ -272,7 +272,7 @@
// need to run later because some other event listeners
// should be called before
loadDocument();
- activateEntry();
+ activateEntry(CURSOR_ON_START_OF_ENTRY);
}
});
break;
@@ -372,7 +372,7 @@
int activeSegment = displayedEntryIndex;
loadDocument();
displayedEntryIndex = activeSegment;
- activateEntry();
+ activateEntry(CURSOR_ON_START_OF_ENTRY);
}
/**
@@ -487,7 +487,7 @@
* <p>
* Also moves document focus to current entry, and makes sure fuzzy info displayed if available.
*/
- public void activateEntry() {
+ public void activateEntry(int preferredPosition) {
UIThreadsUtil.mustBeSwingThread();
- scrollForDisplayNearestSegments(editor.getOmDocument().getTranslationStart());
+ int te = editor.getOmDocument().getTranslationEnd();
+ int ts = editor.getOmDocument().getTranslationStart();
+ int newPosition;
+ //
+ // Navigate to entry as requested.
+ //
+ if (preferredPosition == CURSOR_ON_START_OF_ENTRY)
+ {
+ newPosition = ts;
+ }
+ else if (preferredPosition == CURSOR_ON_END_OF_ENTRY)
+ {
+ newPosition = te;
+ }
+ else if (preferredPosition >= ts && preferredPosition <= te)
+ {
+ newPosition = preferredPosition;
+ }
+ else
+ {
+ // Default is start.
+ newPosition = ts;
+ }
+ scrollForDisplayNearestSegments(newPosition);
// check if file was changed
if (previousDisplayedFileIndex != displayedFileIndex) {
@@ -669,7 +692,7 @@
if (displayedEntryIndex != segmentAtLocation) {
doChangeSegmentActions();
displayedEntryIndex = segmentAtLocation;
- activateEntry();
+ activateEntry(CURSOR_ON_START_OF_ENTRY);
}
}
@@ -787,8 +810,14 @@
* {@inheritDoc}
*/
public void commitAndLeave() {
+ //
+ // Memorize current position of cursor.
+ // After deactivating and activating with shrinking and expanding text, we might
+ // be able to position the current at this position again.
+ //
+ int currentPosition = editor.getCaretPosition();
commitAndDeactivate();
- activateEntry();
+ activateEntry(currentPosition);
}
+ int CURSOR_ON_START_OF_ENTRY = -1;
+ int CURSOR_ON_END_OF_ENTRY = -2;
+
/**
* Get current file name which opened in editor.
*
@@ -76,7 +79,7 @@
*
* Must be called only from UI thread.
*/
- void activateEntry();
+ void activateEntry(int preferredPosition);
/**
* Commits the translation and deactivate entry. Translation will be saved.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I agree, this is annoying. The cursor should remain where it is when you press Ctrl+S. Some of us press Ctrl+S as a matter of course, as a good habit, and we do not when it makes logical sense to do so but when our fingers remember to do it :-)
--leuce
Still applies. Reproduced on trunk, revision 4070.
Cursor also goes to the head of the segment for other actions, such as Edit properties of the project.
Patch is:
Index: src/org/omegat/gui/editor/EditorController.java
--- src/org/omegat/gui/editor/EditorController.java (revision 4070)
+++ src/org/omegat/gui/editor/EditorController.java (working copy)
@@ -272,7 +272,7 @@
// need to run later because some other event listeners
// should be called before
loadDocument();
- activateEntry();
+ activateEntry(CURSOR_ON_START_OF_ENTRY);
}
});
break;
@@ -372,7 +372,7 @@
int activeSegment = displayedEntryIndex;
loadDocument();
displayedEntryIndex = activeSegment;
- activateEntry();
+ activateEntry(CURSOR_ON_START_OF_ENTRY);
}
/**
@@ -487,7 +487,7 @@
* <p>
* Also moves document focus to current entry, and makes sure fuzzy info displayed if available.
*/
- public void activateEntry() {
+ public void activateEntry(int preferredPosition) {
UIThreadsUtil.mustBeSwingThread();
SourceTextEntry ste = getCurrentEntry();
@@ -527,7 +527,30 @@
exportCurrentSegment(ste);
}
- scrollForDisplayNearestSegments(editor.getOmDocument().getTranslationStart());
+ int te = editor.getOmDocument().getTranslationEnd();
+ int ts = editor.getOmDocument().getTranslationStart();
+ int newPosition;
+ //
+ // Navigate to entry as requested.
+ //
+ if (preferredPosition == CURSOR_ON_START_OF_ENTRY)
+ {
+ newPosition = ts;
+ }
+ else if (preferredPosition == CURSOR_ON_END_OF_ENTRY)
+ {
+ newPosition = te;
+ }
+ else if (preferredPosition >= ts && preferredPosition <= te)
+ {
+ newPosition = preferredPosition;
+ }
+ else
+ {
+ // Default is start.
+ newPosition = ts;
+ }
+ scrollForDisplayNearestSegments(newPosition);
// check if file was changed
if (previousDisplayedFileIndex != displayedFileIndex) {
@@ -669,7 +692,7 @@
if (displayedEntryIndex != segmentAtLocation) {
doChangeSegmentActions();
displayedEntryIndex = segmentAtLocation;
- activateEntry();
+ activateEntry(CURSOR_ON_START_OF_ENTRY);
}
}
@@ -787,8 +810,14 @@
* {@inheritDoc}
*/
public void commitAndLeave() {
+ //
+ // Memorize current position of cursor.
+ // After deactivating and activating with shrinking and expanding text, we might
+ // be able to position the current at this position again.
+ //
+ int currentPosition = editor.getCaretPosition();
commitAndDeactivate();
- activateEntry();
+ activateEntry(currentPosition);
}
public void nextEntry() {
@@ -830,7 +859,7 @@
// entries
));
- activateEntry();
+ activateEntry(CURSOR_ON_START_OF_ENTRY);
this.editor.setCursor(oldCursor);
}
@@ -873,7 +902,7 @@
// entries
));
- activateEntry();
+ activateEntry(CURSOR_ON_START_OF_ENTRY);
this.editor.setCursor(oldCursor);
}
@@ -933,7 +962,7 @@
}
} while (true);
- activateEntry();
+ activateEntry(CURSOR_ON_START_OF_ENTRY);
this.editor.setCursor(oldCursor);
}
@@ -966,7 +995,7 @@
displayedEntryIndex = 0;
loadDocument();
- activateEntry();
+ activateEntry(CURSOR_ON_START_OF_ENTRY);
}
/**
@@ -1016,7 +1045,7 @@
}
}
}
- activateEntry();
+ activateEntry(CURSOR_ON_START_OF_ENTRY);
this.editor.setCursor(oldCursor);
}
Index: src/org/omegat/gui/editor/IEditor.java
--- src/org/omegat/gui/editor/IEditor.java (revision 4070)
+++ src/org/omegat/gui/editor/IEditor.java (working copy)
@@ -50,6 +50,9 @@
CYCLE,
}
+ int CURSOR_ON_START_OF_ENTRY = -1;
+ int CURSOR_ON_END_OF_ENTRY = -2;
+
/**
* Get current file name which opened in editor.
*
@@ -76,7 +79,7 @@
*
* Must be called only from UI thread.
*/
- void activateEntry();
+ void activateEntry(int preferredPosition);
/**
* Commits the translation and deactivate entry. Translation will be saved.
Fixed in SVN (/trunk).
Note that the patch listed here was not enough, it wouldn't compile.
Didier
Closing...
This bug was corrected in the released version 2.5.1 update 1 of OmegaT.