X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Fbits%2FMnemonicString.java;h=2d5dbc8cd2533ebb8697b247a744ea2b82aa3202;hb=6582df7ecd410f7aebf9c32ddba885b806ad393e;hp=d0032b6683ad497b3d223586f45dcf7264f8d447;hpb=43ad7b6c509c45c8f261e77ea059c10fed8c9f1c;p=fanfix.git diff --git a/src/jexer/bits/MnemonicString.java b/src/jexer/bits/MnemonicString.java index d0032b6..2d5dbc8 100644 --- a/src/jexer/bits/MnemonicString.java +++ b/src/jexer/bits/MnemonicString.java @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (C) 2017 Kevin Lamonte + * Copyright (C) 2019 Kevin Lamonte * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -34,7 +34,7 @@ package jexer.bits; * two '&&' characters, e.g. "&File && Stuff" would be * "File & Stuff" with the first 'F' highlighted. */ -public final class MnemonicString { +public class MnemonicString { // ------------------------------------------------------------------------ // Variables -------------------------------------------------------------- @@ -50,6 +50,12 @@ public final 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 final 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 final class MnemonicString { foundAmp = false; foundShortcut = true; shortcutIdx = scanShortcutIdx; + screenShortcutIdx = scanScreenShortcutIdx; } } else { scanShortcutIdx++; + scanScreenShortcutIdx += StringUtils.width(c); } } } @@ -120,6 +130,16 @@ public final 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. *