Skip to content

Commit 32f2a0c

Browse files
committedFeb 25, 2023
Configured to prefer running on local client when using remote ssh connection, fixing the random loss of mark selection.
1 parent 01d0ae9 commit 32f2a0c

10 files changed

+1114
-2456
lines changed
 

‎.eslintrc.json

-24
This file was deleted.

‎.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
/out
22
/node_modules
3-
/notes

‎.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
save = true

‎.vscodeignore

-10
This file was deleted.

‎CHANGELOG.md

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
# Change Log
22

3-
All notable changes to the "foobar" extension will be documented in this file.
4-
5-
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
6-
7-
## [Unreleased]
8-
93
## [1.0.0 - 1.0.7] - 2016-06-29 - 2016-07-14
104
- Initial releases
115

126
## [1.1.0] - 2021-10-19
137
- Updated extension to latest standards
148
- Fix bug where extension failed on attempted os-level copy on non-darwin systems, breaking ssh-remoting to linux systems.
9+
10+
## [1.1.1] - 2023-02-25
11+
- Configured to prefer running on local client when using remote ssh connection, fixing the random loss of mark selection.

‎package-lock.json

+617-1,948
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+339-345
Large diffs are not rendered by default.

‎src/extension.ts

-116
This file was deleted.

‎src/main.ts

+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
import { execSync } from 'child_process';
2+
import * as os from 'os';
3+
import {
4+
commands,
5+
Disposable,
6+
ExtensionContext,
7+
TextEditorRevealType,
8+
window,
9+
workspace,
10+
} from 'vscode';
11+
12+
export function deactivate() {}
13+
14+
export function activate(context: ExtensionContext) {
15+
let nemacs = new Nemacs();
16+
context.subscriptions.push(
17+
commands.registerCommand("nemacs.mark", () => {
18+
nemacs.mark();
19+
}),
20+
);
21+
for (let cmd of [
22+
"cursorUp",
23+
"cursorDown",
24+
"cursorLeft",
25+
"cursorRight",
26+
"cursorHome",
27+
"cursorEnd",
28+
"cursorPageUp",
29+
"cursorPageDown",
30+
]) {
31+
context.subscriptions.push(
32+
commands.registerCommand(`nemacs.${cmd}`, () => {
33+
nemacs.cursorMove(cmd);
34+
}),
35+
);
36+
}
37+
context.subscriptions.push(
38+
commands.registerCommand("nemacs.killLine", () => {
39+
nemacs.killLine();
40+
}),
41+
);
42+
context.subscriptions.push(
43+
commands.registerCommand("nemacs.yank", () => {
44+
nemacs.yank();
45+
}),
46+
);
47+
context.subscriptions.push(
48+
commands.registerCommand("nemacs.copy", () => {
49+
nemacs.copy();
50+
}),
51+
);
52+
context.subscriptions.push(
53+
commands.registerCommand("nemacs.centerVertically", () => {
54+
nemacs.centerVertically();
55+
}),
56+
);
57+
context.subscriptions.push(nemacs);
58+
}
59+
60+
class Nemacs {
61+
private disposable: Disposable;
62+
private marked: boolean = false;
63+
private moving: boolean = false;
64+
private ringBuffer: string = "";
65+
66+
constructor() {
67+
let subscriptions: Disposable[] = [];
68+
window.onDidChangeTextEditorSelection(
69+
this.onDidChangeTextEditorSelection,
70+
this,
71+
subscriptions,
72+
);
73+
this.disposable = Disposable.from(...subscriptions);
74+
}
75+
76+
public mark() {
77+
this.marked = true;
78+
}
79+
80+
public cursorMove(command: string) {
81+
if (this.marked) {
82+
this.moving = true;
83+
commands.executeCommand(`${command}Select`).then(() => {
84+
this.moving = false;
85+
});
86+
} else {
87+
commands.executeCommand(command);
88+
}
89+
}
90+
91+
private copyRingBuffer() {
92+
if (this.ringBuffer) {
93+
if (os.platform() === "darwin") {
94+
execSync("pbcopy", { input: this.ringBuffer });
95+
}
96+
this.ringBuffer = "";
97+
}
98+
}
99+
100+
private onDidChangeTextEditorSelection() {
101+
if (this.marked && !this.moving) {
102+
this.cancelSelection();
103+
}
104+
this.copyRingBuffer();
105+
}
106+
107+
public cancelSelection() {
108+
this.marked = false;
109+
this.moving = false;
110+
commands.executeCommand("cancelSelection");
111+
}
112+
113+
public killLine() {
114+
if (!window.activeTextEditor) return;
115+
let sel = window.activeTextEditor.selection;
116+
let line = window.activeTextEditor.document.lineAt(sel.active.line);
117+
if (this.marked) {
118+
commands.executeCommand("editor.action.clipboardCutAction");
119+
} else if (line.range.end.character === sel.active.character) {
120+
if (line.lineNumber < window.activeTextEditor.document.lineCount - 1) {
121+
this.ringBuffer =
122+
this.ringBuffer + workspace.getConfiguration("files").get("eol");
123+
commands.executeCommand("deleteRight");
124+
}
125+
} else {
126+
this.ringBuffer =
127+
this.ringBuffer +
128+
line.text.substring(sel.active.character, line.range.end.character);
129+
commands.executeCommand("deleteAllRight");
130+
}
131+
}
132+
133+
public yank() {
134+
this.copyRingBuffer();
135+
commands.executeCommand("editor.action.clipboardPasteAction");
136+
}
137+
138+
public copy() {
139+
commands.executeCommand("editor.action.clipboardCopyAction");
140+
this.cancelSelection();
141+
}
142+
143+
public centerVertically() {
144+
window.activeTextEditor?.revealRange(
145+
window.activeTextEditor.selection.with(),
146+
TextEditorRevealType.InCenter,
147+
);
148+
}
149+
150+
dispose() {
151+
this.disposable.dispose();
152+
}
153+
}

‎tsconfig.json

+1-6
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,9 @@
88
],
99
"sourceMap": true,
1010
"rootDir": "src",
11-
"strict": true /* enable all strict type-checking options */
12-
/* Additional Checks */
13-
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
14-
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
15-
// "noUnusedParameters": true, /* Report errors on unused parameters. */
11+
"strict": true
1612
},
1713
"exclude": [
1814
"node_modules",
19-
".vscode-test"
2015
]
2116
}

0 commit comments

Comments
 (0)
Please sign in to comment.