-
Notifications
You must be signed in to change notification settings - Fork 15
/
mode.ts
55 lines (41 loc) · 1.59 KB
/
mode.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import * as vscode from "vscode";
import { configuration } from "./configuration";
const defaultMode = false;
const state = {
global: defaultMode,
perEditor: new WeakMap<vscode.TextEditor, boolean>()
};
export function getMode(textEditor: vscode.TextEditor) {
if (!configuration.perEditor) {
return state.global;
}
if (!state.perEditor.has(textEditor)) {
state.perEditor.set(textEditor, defaultMode);
}
return <boolean>state.perEditor.get(textEditor);
}
export function toggleMode(textEditor: vscode.TextEditor) {
let overtype = !getMode(textEditor);
if (!configuration.perEditor) {
state.global = overtype;
} else {
state.perEditor.set(textEditor, overtype);
}
return overtype;
}
export function resetModes(mode: boolean | null, perEditor: boolean) {
if (mode === null) mode = defaultMode;
if (perEditor) {
// when switching from global to per-editor, reset the global mode to default
// and (currently impossible) set all editors to the provided mode
// future: this should enumerate all open editors and set their mode explicitly
// tracking: https://github.com/Microsoft/vscode/issues/15178
state.global = defaultMode;
state.perEditor = state.perEditor = new WeakMap<vscode.TextEditor, boolean>();
} else {
// when switching from per-editor to global, set the global mode to the
// provided mode and reset all per-editor modes
state.global = mode;
state.perEditor = state.perEditor = new WeakMap<vscode.TextEditor, boolean>();
}
}