Menu

#284 After "save" the cursor goes to the head of the segment

2.5
closed-fixed
1
2012-02-27
2007-01-24
No

If one saves while editing a segment, the cursor goes automatically to the head of the segment.

the cursor should not change of position after a save.

Discussion

  • Didier Briel

    Didier Briel - 2007-09-22
    • priority: 5 --> 1
     
  • Nobody/Anonymous

    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

     
  • Guido Leenders

    Guido Leenders - 2012-02-05

    Still applies. Reproduced on trunk, revision 4070.

     
  • Guido Leenders

    Guido Leenders - 2012-02-05

    Cursor also goes to the head of the segment for other actions, such as Edit properties of the project.

     
  • Guido Leenders

    Guido Leenders - 2012-02-05

    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.

     
  • Didier Briel

    Didier Briel - 2012-02-17
    • milestone: 667985 --> 2.5
    • assigned_to: nobody --> guido_leenders
    • summary: after "save" the cursor goes to the head of the segment --> After "save" the cursor goes to the head of the segment
     
  • Didier Briel

    Didier Briel - 2012-02-17

    Fixed in SVN (/trunk).

    Note that the patch listed here was not enough, it wouldn't compile.

    Didier

     
  • Didier Briel

    Didier Briel - 2012-02-27
    • status: open --> closed-fixed
     
  • Didier Briel

    Didier Briel - 2012-02-27

    Closing...
    This bug was corrected in the released version 2.5.1 update 1 of OmegaT.

     

Log in to post a comment.