fix(input): add sliding-window multi-tap candidate bar and input tail-scrolling across plugins and fcitx5-t9
This commit is contained in:
1 parent
a53a331111
commit
1f9138f0c6
24 files changed
+394
-125
No files matched your search
@@ -53,44 +53,44 @@ enum class TextCaseMode {
|
||||
};
|
||||
|
||||
const char* kMultiTapFile[10] = {
|
||||
" _-0", // 0
|
||||
".-_1", // 1
|
||||
"abc2", // 2
|
||||
"def3", // 3
|
||||
"ghi4", // 4
|
||||
"jkl5", // 5
|
||||
"mno6", // 6
|
||||
"pqrs7", // 7
|
||||
"tuv8", // 8
|
||||
"wxyz9" // 9
|
||||
" _-0", // 0
|
||||
".-_1,!?+@#$%~()[]{}", // 1
|
||||
"abc2", // 2
|
||||
"def3", // 3
|
||||
"ghi4", // 4
|
||||
"jkl5", // 5
|
||||
"mno6", // 6
|
||||
"pqrs7", // 7
|
||||
"tuv8", // 8
|
||||
"wxyz9" // 9
|
||||
};
|
||||
|
||||
const char* kMultiTapEditorAlpha[11] = {
|
||||
" 0", // 0
|
||||
".,:;!?-_1/\"'()", // 1
|
||||
"abc2", // 2
|
||||
"def3", // 3
|
||||
"ghi4", // 4
|
||||
"jkl5", // 5
|
||||
"mno6", // 6
|
||||
"pqrs7", // 7
|
||||
"tuv8", // 8
|
||||
"wxyz9", // 9
|
||||
".,!?+-*/=<>()[]{}\"'_#$%&|\\~^@" // 10 (*)
|
||||
" 0", // 0
|
||||
kMultiTapPunct1, // 1
|
||||
"abc2", // 2
|
||||
"def3", // 3
|
||||
"ghi4", // 4
|
||||
"jkl5", // 5
|
||||
"mno6", // 6
|
||||
"pqrs7", // 7
|
||||
"tuv8", // 8
|
||||
"wxyz9", // 9
|
||||
kMultiTapStar // 10 (*)
|
||||
};
|
||||
|
||||
const char* kMultiTapEditorSym[11] = {
|
||||
" _0", // 0
|
||||
".,:;!?1", // 1
|
||||
"\"'`~@2", // 2
|
||||
"()[]{}<>3", // 3
|
||||
"+-*/=%4", // 4
|
||||
"|&^#$5", // 5
|
||||
"_\\/$@6", // 6
|
||||
"=<>!~7", // 7
|
||||
"();,\"8", // 8
|
||||
"{}[]#9", // 9
|
||||
"+-*/=<>()[]{}\"'.,:;!?_|&^#$%~@\\" // 10 (*)
|
||||
" _0", // 0
|
||||
".,:;!?-_1", // 1
|
||||
"\"'`~@#2", // 2
|
||||
"()[]{}<>3", // 3
|
||||
"+-*/=%4", // 4
|
||||
"|&^#$5", // 5
|
||||
"_\\/$@6", // 6
|
||||
"=<>!~7", // 7
|
||||
"();,\"8", // 8
|
||||
"{}[]#9", // 9
|
||||
kMultiTapStar // 10 (*)
|
||||
};
|
||||
|
||||
struct FileItem {
|
||||
@@ -1184,11 +1184,20 @@ int runFilesApp(int argc, char** argv) {
|
||||
XFillRectangle(dpy, pix, gc, 10, 74, kWinWidth - 20, 38);
|
||||
XSetForeground(dpy, gc, pt.spec.accentAlt);
|
||||
XDrawRectangle(dpy, pix, gc, 10, 74, kWinWidth - 21, 37);
|
||||
drawPango(layoutMain, &colWhite, 16, 74, 38, inputValue + "|",
|
||||
kWinWidth - 32);
|
||||
std::string modalDisp =
|
||||
tailFitPangoText(layoutMain, inputValue + "|", kWinWidth - 32);
|
||||
drawPango(layoutMain, &colWhite, 16, 74, 38, modalDisp, kWinWidth - 32);
|
||||
|
||||
drawPango(layoutSmall, &colMuted, 10, 126, 20,
|
||||
"# Input mode", 220);
|
||||
if (lastTapDigit >= 0 && lastTapDigit <= 9 &&
|
||||
(nowMs() - lastTapMs) <= 850) {
|
||||
std::string cand = formatMultiTapBar(
|
||||
std::to_string(lastTapDigit) + ":", kMultiTapFile[lastTapDigit],
|
||||
lastTapCycle, caseMode == TextCaseMode::Upper);
|
||||
drawPango(layoutSmall, &colYellow, 10, 126, 20, cand, 220);
|
||||
} else {
|
||||
drawPango(layoutSmall, &colMuted, 10, 126, 20,
|
||||
"#:Mode *:Punct Right:Next", 220);
|
||||
}
|
||||
drawSoftkeyBar("Save", "Save",
|
||||
inputValue.empty() ? "Cancel" : "Del");
|
||||
|
||||
@@ -1279,8 +1288,28 @@ int runFilesApp(int argc, char** argv) {
|
||||
|
||||
const std::string& rawLine = editLines[idx];
|
||||
size_t sliceStart = 0;
|
||||
if (isCurRow && editCursorCol > 22) {
|
||||
sliceStart = clampUtf8Pos(rawLine, editCursorCol - 22);
|
||||
int cx = 0;
|
||||
const int maxLineTextW = kWinWidth - gutterW - 10;
|
||||
if (isCurRow) {
|
||||
size_t curByte =
|
||||
static_cast<size_t>(clampUtf8Pos(rawLine, editCursorCol));
|
||||
if (curByte > 22) {
|
||||
sliceStart =
|
||||
static_cast<size_t>(clampUtf8Pos(rawLine, editCursorCol - 22));
|
||||
}
|
||||
while (sliceStart < curByte) {
|
||||
std::string beforeCur = expandTabsForDisplay(
|
||||
rawLine.substr(sliceStart, curByte - sliceStart));
|
||||
pango_layout_set_width(layoutSmall, -1);
|
||||
pango_layout_set_ellipsize(layoutSmall, PANGO_ELLIPSIZE_NONE);
|
||||
pango_layout_set_text(layoutSmall, beforeCur.c_str(),
|
||||
static_cast<int>(beforeCur.size()));
|
||||
int chh = 0;
|
||||
pango_layout_get_pixel_size(layoutSmall, &cx, &chh);
|
||||
if (cx <= maxLineTextW - 6) break;
|
||||
sliceStart = static_cast<size_t>(
|
||||
nextUtf8Pos(rawLine, static_cast<int>(sliceStart)));
|
||||
}
|
||||
}
|
||||
std::string rawSlice = rawLine.substr(sliceStart);
|
||||
std::string dispSlice = expandTabsForDisplay(rawSlice);
|
||||
@@ -1289,16 +1318,6 @@ int runFilesApp(int argc, char** argv) {
|
||||
ry, rowH, dispSlice, kWinWidth - gutterW - 8);
|
||||
|
||||
if (isCurRow && !editMenuOpen) {
|
||||
size_t curOff =
|
||||
(editCursorCol >= sliceStart) ? (editCursorCol - sliceStart) : 0;
|
||||
std::string beforeCur =
|
||||
expandTabsForDisplay(rawSlice.substr(0, curOff));
|
||||
pango_layout_set_width(layoutSmall, -1);
|
||||
pango_layout_set_ellipsize(layoutSmall, PANGO_ELLIPSIZE_NONE);
|
||||
pango_layout_set_text(layoutSmall, beforeCur.c_str(),
|
||||
static_cast<int>(beforeCur.size()));
|
||||
int cx = 0, chh = 0;
|
||||
pango_layout_get_pixel_size(layoutSmall, &cx, &chh);
|
||||
int curX = std::min(kWinWidth - 4, gutterW + 4 + cx);
|
||||
XSetForeground(dpy, gc,
|
||||
tapActive ? pt.spec.success : pt.spec.accentAlt);
|
||||
@@ -1318,24 +1337,13 @@ int runFilesApp(int argc, char** argv) {
|
||||
(editCaseMode == TextCaseMode::Sym)
|
||||
? kMultiTapEditorSym[editLastTapDigit]
|
||||
: kMultiTapEditorAlpha[editLastTapDigit];
|
||||
int tlen = static_cast<int>(std::strlen(table));
|
||||
std::string cand =
|
||||
std::string pref =
|
||||
(editLastTapDigit == 10)
|
||||
? "*: "
|
||||
: (std::to_string(editLastTapDigit) + ": ");
|
||||
for (int k = 0; k < tlen; ++k) {
|
||||
char c = table[k];
|
||||
if (std::isalpha(static_cast<unsigned char>(c)) &&
|
||||
editCaseMode == TextCaseMode::Upper) {
|
||||
c = static_cast<char>(std::toupper(static_cast<unsigned char>(c)));
|
||||
}
|
||||
std::string label = (c == ' ') ? "SPC" : std::string(1, c);
|
||||
if (k == editLastTapCycle) {
|
||||
cand += "[" + label + "] ";
|
||||
} else {
|
||||
cand += label + " ";
|
||||
}
|
||||
}
|
||||
? "*:"
|
||||
: (std::to_string(editLastTapDigit) + ":");
|
||||
std::string cand = formatMultiTapBar(
|
||||
pref, table, editLastTapCycle,
|
||||
editCaseMode == TextCaseMode::Upper);
|
||||
drawPango(layoutSmall, &colYellow, 6, hintY, 20, cand, kWinWidth - 12);
|
||||
} else {
|
||||
drawPango(layoutSmall, &colMuted, 6, hintY, 20,
|
||||
@@ -2116,6 +2124,7 @@ int runFilesApp(int argc, char** argv) {
|
||||
handleSoftkeyAction(true);
|
||||
} else if (sym == XK_Right || sym == XK_KP_Right) {
|
||||
lastTapDigit = -1;
|
||||
drawUI();
|
||||
} else {
|
||||
char d = mapDialKey(sym, kc, ev.xkey.state);
|
||||
if (d == '#') {
|
||||
@@ -2159,6 +2168,11 @@ int runFilesApp(int argc, char** argv) {
|
||||
editLastTapDigit = -1;
|
||||
drawUI();
|
||||
}
|
||||
if (visible && mode == ViewMode::InputModal && lastTapDigit != -1 &&
|
||||
(tNow - lastTapMs) > 850) {
|
||||
lastTapDigit = -1;
|
||||
drawUI();
|
||||
}
|
||||
|
||||
int timeoutMs = -1;
|
||||
if (visible && softkeyPending != 0) {
|
||||
@@ -2168,6 +2182,10 @@ int runFilesApp(int argc, char** argv) {
|
||||
int tapRem = std::max(1, static_cast<int>(851 - (tNow - editLastTapMs)));
|
||||
timeoutMs = (timeoutMs < 0) ? tapRem : std::min(timeoutMs, tapRem);
|
||||
}
|
||||
if (visible && mode == ViewMode::InputModal && lastTapDigit != -1) {
|
||||
int tapRem = std::max(1, static_cast<int>(851 - (tNow - lastTapMs)));
|
||||
timeoutMs = (timeoutMs < 0) ? tapRem : std::min(timeoutMs, tapRem);
|
||||
}
|
||||
if (visible && !statusBanner.empty() && statusBannerUntilMs > 0) {
|
||||
if (tNow >= statusBannerUntilMs) {
|
||||
statusBanner.clear();
|
||||
|
||||
Reference in new issue
Block a user