Skip to content

Instantly share code, notes, and snippets.

@yu-tang
Created March 12, 2017 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yu-tang/ebe5a3aa32e0e6a0234edc6294801fda to your computer and use it in GitHub Desktop.
Save yu-tang/ebe5a3aa32e0e6a0234edc6294801fda to your computer and use it in GitHub Desktop.
Display segment at the bottom of the Editor when you activate new segment
/* :name=Display segment at the bottom :description=Display segment at the bottom of the Editor when you activate new segment
*
* Usage: move this script to
* <your-scripts-folder>/entry_activated/ sub-folder
* for event driven automatically execution.
*
* @author Yu Tang
* @date 2017-03-12
* @version 0.1.0
*/
package me.goat.groovy.scripting
import java.awt.Rectangle
// see org.omegat.gui.editor.EditorController#scrollForDisplayNearestSegments(CaretPosition) for details
int displayedEntryIndex = editor.displayedEntryIndex
Rectangle rect = editor.getSegmentBounds(displayedEntryIndex)
if (rect) {
// Expand rect vertically to fill height of viewport.
int viewportHeight = editor.scrollPane.viewport.height
int fontSize = editor.editor.font.size
rect.y -= (viewportHeight - rect.height + fontSize)
rect.height = viewportHeight
editor.editor.scrollRectToVisible(rect)
}
"display_segment_at_the_bottom.groovy executed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment