Skip to content

Commit f09306a

Browse files
committed
feat: avoid control characters in cmdline
1 parent 8dc7e3f commit f09306a

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

denops/fall/component/input.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,6 @@ export class InputComponent extends BaseComponent {
216216
2,
217217
);
218218

219-
// TODO:
220-
// When 'cmdline' includes control characters that is displayed like '^Y', the display width
221-
// is not equal to the length of the string. So we need to slice 'middle' to fit in the cmdwidth
222-
// properly.
223219
const spacer = " ".repeat(cmdwidth);
224220
const middle = `${this.#cmdline}${spacer}`.slice(
225221
this.#offset,

denops/fall/util/cmdliner.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import { collect } from "jsr:@denops/std@^7.3.2/batch";
77

88
import { dispatch } from "../event.ts";
99

10+
// deno-lint-ignore no-control-regex
11+
const CONTROL_CHARACTERS = /[\x00-\x1f\x7f]/g;
12+
1013
export class Cmdliner {
1114
#cmdline: string;
1215
#cmdpos: number;
@@ -72,6 +75,14 @@ export class Cmdliner {
7275
// Not in command-line mode
7376
return;
7477
}
78+
// Check control characters in cmdline
79+
if (CONTROL_CHARACTERS.test(cmdline)) {
80+
// remove control characters
81+
await fn.setcmdline(denops, cmdline.replace(CONTROL_CHARACTERS, ""));
82+
// retry check
83+
await this.check(denops);
84+
return;
85+
}
7586
if (cmdline !== this.#cmdline) {
7687
dispatch({ type: "vim-cmdline-changed", cmdline });
7788
}

0 commit comments

Comments
 (0)