Skip to content

Commit b2ea1e6

Browse files
committed
refactor: convert js to ts
1 parent 8abffb4 commit b2ea1e6

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import StatusBar from './statusbar'
55

66
export function initVimMode(
77
editor: editor.IStandaloneCodeEditor,
8-
statusbarNode = null,
8+
statusbarNode: Node,
99
StatusBarClass = StatusBar,
1010
sanitizer = null,
1111
) {
@@ -19,7 +19,7 @@ export function initVimMode(
1919
const statusBar = new StatusBarClass(statusbarNode, editor, sanitizer)
2020
let keyBuffer = ''
2121

22-
vimAdapter.on('vim-mode-change', (mode) => {
22+
vimAdapter.on('vim-mode-change', (mode: { mode: string }) => {
2323
statusBar.setMode(mode)
2424
})
2525

src/statusbar.js renamed to src/statusbar.ts

+20-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1+
import { editor } from 'monaco-editor'
2+
13
export default class VimStatusBar {
2-
constructor(node, editor, sanitizer = null) {
4+
private node: HTMLElement
5+
6+
private editor: editor.IStandaloneCodeEditor
7+
8+
private modeInfoNode = document.createElement('span')
9+
10+
private secInfoNode = document.createElement('span')
11+
12+
private notifNode = document.createElement('span')
13+
14+
private keyInfoNode = document.createElement('span')
15+
16+
private sanitizer: null | ((content: string) => string)
17+
18+
constructor(node: HTMLElement, editor: editor.IStandaloneCodeEditor, sanitizer = null) {
319
this.node = node
4-
this.modeInfoNode = document.createElement('span')
5-
this.secInfoNode = document.createElement('span')
6-
this.notifNode = document.createElement('span')
720
this.notifNode.className = 'vim-notification'
8-
this.keyInfoNode = document.createElement('span')
921
this.keyInfoNode.setAttribute('style', 'float: right')
1022
this.node.appendChild(this.modeInfoNode)
1123
this.node.appendChild(this.secInfoNode)
@@ -16,7 +28,7 @@ export default class VimStatusBar {
1628
this.sanitizer = sanitizer
1729
}
1830

19-
setMode(ev) {
31+
setMode(ev: { mode: string; subMode: string }) {
2032
if (ev.mode === 'visual' && ev.subMode === 'linewise') {
2133
this.setText('--VISUAL LINE--')
2234
return
@@ -25,7 +37,7 @@ export default class VimStatusBar {
2537
this.setText(`--${ev.mode.toUpperCase()}--`)
2638
}
2739

28-
setKeyBuffer(key) {
40+
setKeyBuffer(key: string) {
2941
this.keyInfoNode.textContent = key
3042
}
3143

@@ -66,7 +78,7 @@ export default class VimStatusBar {
6678
this.modeInfoNode.textContent = text
6779
}
6880

69-
toggleVisibility(toggle) {
81+
toggleVisibility(toggle: boolean) {
7082
if (toggle) {
7183
this.node.style.display = 'block'
7284
} else {

0 commit comments

Comments
 (0)