Skip to content

Commit

Permalink
refactor: convert js to ts
Browse files Browse the repository at this point in the history
  • Loading branch information
pjshy committed Dec 26, 2019
1 parent 8abffb4 commit b2ea1e6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import StatusBar from './statusbar'

export function initVimMode(
editor: editor.IStandaloneCodeEditor,
statusbarNode = null,
statusbarNode: Node,
StatusBarClass = StatusBar,
sanitizer = null,
) {
Expand All @@ -19,7 +19,7 @@ export function initVimMode(
const statusBar = new StatusBarClass(statusbarNode, editor, sanitizer)
let keyBuffer = ''

vimAdapter.on('vim-mode-change', (mode) => {
vimAdapter.on('vim-mode-change', (mode: { mode: string }) => {
statusBar.setMode(mode)
})

Expand Down
28 changes: 20 additions & 8 deletions src/statusbar.js → src/statusbar.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import { editor } from 'monaco-editor'

export default class VimStatusBar {
constructor(node, editor, sanitizer = null) {
private node: HTMLElement

private editor: editor.IStandaloneCodeEditor

private modeInfoNode = document.createElement('span')

private secInfoNode = document.createElement('span')

private notifNode = document.createElement('span')

private keyInfoNode = document.createElement('span')

private sanitizer: null | ((content: string) => string)

constructor(node: HTMLElement, editor: editor.IStandaloneCodeEditor, sanitizer = null) {
this.node = node
this.modeInfoNode = document.createElement('span')
this.secInfoNode = document.createElement('span')
this.notifNode = document.createElement('span')
this.notifNode.className = 'vim-notification'
this.keyInfoNode = document.createElement('span')
this.keyInfoNode.setAttribute('style', 'float: right')
this.node.appendChild(this.modeInfoNode)
this.node.appendChild(this.secInfoNode)
Expand All @@ -16,7 +28,7 @@ export default class VimStatusBar {
this.sanitizer = sanitizer
}

setMode(ev) {
setMode(ev: { mode: string; subMode: string }) {
if (ev.mode === 'visual' && ev.subMode === 'linewise') {
this.setText('--VISUAL LINE--')
return
Expand All @@ -25,7 +37,7 @@ export default class VimStatusBar {
this.setText(`--${ev.mode.toUpperCase()}--`)
}

setKeyBuffer(key) {
setKeyBuffer(key: string) {
this.keyInfoNode.textContent = key
}

Expand Down Expand Up @@ -66,7 +78,7 @@ export default class VimStatusBar {
this.modeInfoNode.textContent = text
}

toggleVisibility(toggle) {
toggleVisibility(toggle: boolean) {
if (toggle) {
this.node.style.display = 'block'
} else {
Expand Down

0 comments on commit b2ea1e6

Please sign in to comment.