X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Fbits%2FMnemonicString.java;h=2d5dbc8cd2533ebb8697b247a744ea2b82aa3202;hb=9f613a0c54cb97e9305fd87ce8eb2f76ac82804e;hp=5977ed56c71064262d19f0fed0afc15686ffd59e;hpb=0c28ec38449a59cf34cf5b3c13ea02add1ee57c5;p=fanfix.git diff --git a/src/jexer/bits/MnemonicString.java b/src/jexer/bits/MnemonicString.java index 5977ed5..2d5dbc8 100644 --- a/src/jexer/bits/MnemonicString.java +++ b/src/jexer/bits/MnemonicString.java @@ -50,6 +50,12 @@ public class MnemonicString { */ private int shortcutIdx = -1; + /** + * Screen location of the highlighted character (number of text cells + * required to display from the beginning to shortcutIdx). + */ + private int screenShortcutIdx = -1; + /** * The raw (uncolored) string. */ @@ -72,12 +78,14 @@ public class MnemonicString { boolean foundAmp = false; boolean foundShortcut = false; int scanShortcutIdx = 0; + int scanScreenShortcutIdx = 0; for (int i = 0; i < label.length(); i++) { char c = label.charAt(i); if (c == '&') { if (foundAmp) { newLabel += '&'; scanShortcutIdx++; + scanScreenShortcutIdx++; } else { foundAmp = true; } @@ -89,9 +97,11 @@ public class MnemonicString { foundAmp = false; foundShortcut = true; shortcutIdx = scanShortcutIdx; + screenShortcutIdx = scanScreenShortcutIdx; } } else { scanShortcutIdx++; + scanScreenShortcutIdx += StringUtils.width(c); } } } @@ -120,6 +130,16 @@ public class MnemonicString { return shortcutIdx; } + /** + * Get the screen location of the highlighted character. + * + * @return the number of text cells required to display from the + * beginning of the label to shortcutIdx + */ + public int getScreenShortcutIdx() { + return screenShortcutIdx; + } + /** * Get the raw (uncolored) string. *