diff --git a/src/main.tsx b/src/main.tsx index b97f21f6..1fd0a0e5 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -241,6 +241,11 @@ class TextAreaInput extends React.Component<{onHeightChange : () => void}, {}> { this.controlU(); return; } + if (e.code == "KeyW" && e.getModifierState("Control")) { + e.preventDefault(); + this.controlW(); + return; + } if (e.code == "KeyY" && e.getModifierState("Control")) { e.preventDefault(); this.controlY(); @@ -394,6 +399,40 @@ class TextAreaInput extends React.Component<{onHeightChange : () => void}, {}> { GlobalModel.inputModel.updateCmdLine(cmdLineUpdate); } + @boundMethod + controlW() { + if (this.mainInputRef.current == null) { + return; + } + let selStart = this.mainInputRef.current.selectionStart; + let value = this.mainInputRef.current.value; + if (selStart > value.length) { + return; + } + let cutSpot = selStart-1; + let initial = true; + for (;cutSpot>=0; cutSpot--) { + let ch = value[cutSpot]; + console.log(cutSpot, "[" + ch + "]"); + if (ch == " " && initial) { + continue; + } + initial = false; + if (ch == " ") { + cutSpot++; + break; + } + } + let cutValue = value.slice(cutSpot, selStart); + let prevValue = value.slice(0, cutSpot); + let restValue = value.slice(selStart); + let cmdLineUpdate = {cmdline: prevValue + restValue, cursorpos: prevValue.length}; + console.log("ss", selStart, value, "prev[" + prevValue + "]", "cut[" + cutValue + "]", "rest[" + restValue + "]"); + console.log(" ", cmdLineUpdate); + navigator.clipboard.writeText(cutValue); + GlobalModel.inputModel.updateCmdLine(cmdLineUpdate); + } + @boundMethod controlY() { if (this.mainInputRef.current == null) { @@ -486,8 +525,8 @@ class TextAreaInput extends React.Component<{onHeightChange : () => void}, {}> { } return (
- - + +
); }