Created
May 5, 2017 12:20
-
-
Save yu-tang/82c2f92cf69ca7c64bc0115a325b608a to your computer and use it in GitHub Desktop.
Set caret position at the segment tail end when goto previous segment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package me.goat.groovy.scripting.tailedcaret | |
import javax.swing.SwingUtilities | |
import org.omegat.core.Core | |
import org.omegat.core.CoreEvents | |
import org.omegat.core.data.SourceTextEntry | |
import org.omegat.core.events.IEntryEventListener | |
import org.omegat.gui.editor.Document3 | |
import org.omegat.util.gui.UIThreadsUtil | |
// add the listener | |
CoreEvents.registerEntryEventListener new EntryEventListener({ | |
UIThreadsUtil.mustBeSwingThread() | |
Document3 doc = editor.editor.omDocument | |
editor.editor.caret.dot = doc.translationEnd | |
}) | |
class EntryEventListener implements IEntryEventListener { | |
Closure onPrevEntry | |
int startEntryNumber = 0 | |
// constructor | |
EntryEventListener(Closure onPrevEntry) { | |
this.onPrevEntry = onPrevEntry | |
} | |
@Override | |
void onNewFile(String activeFileName) { | |
// do nothing | |
} | |
@Override | |
void onEntryActivated(SourceTextEntry newEntry) { | |
int i = newEntry.entryNum() | |
if (i - startEntryNumber == -1) { | |
onPreviousEntry() | |
} else if (startEntryNumber == 1 && i == Core.project.allEntries.size()) { | |
onPreviousEntry() | |
} | |
startEntryNumber = i | |
} | |
private onPreviousEntry() { | |
onPrevEntry.call() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
使い方:
scripts/application_startup フォルダーに入れておく(自動実行)か、任意のタイミングで手動実行する。