Skip to content

Commit

Permalink
feat(events): add bufnr property for current bufnr
Browse files Browse the repository at this point in the history
  • Loading branch information
chemzqm committed Apr 5, 2022
1 parent 177abe5 commit c136a60
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class Events {

private handlers: Map<string, ((...args: any[]) => Promise<unknown>)[]> = new Map()
private _cursor: CursorPosition
private _bufnr: number
// bufnr & character
private _recentInserts: [number, string][] = []
private _lastChange = 0
Expand All @@ -91,6 +92,10 @@ class Events {
return this._cursor
}

public get bufnr(): number {
return this._bufnr
}

public get pumvisible(): boolean {
return this._pumVisible
}
Expand Down Expand Up @@ -166,6 +171,8 @@ class Events {
this._recentInserts.push([args[1], args[0]])
} else if (event == 'TextChanged') {
this._lastChange = Date.now()
} else if (event == 'BufEnter') {
this._bufnr = args[0]
}
if (event == 'TextChangedI' || event == 'TextChangedP') {
let arr = this._recentInserts.filter(o => o[0] == args[0])
Expand All @@ -185,11 +192,13 @@ class Events {
}
}
if ((event == 'CursorHold' || event == 'CursorHoldI') && args[1]) {
this._bufnr = args[0]
let ev: LastHold = { bufnr: args[0], lnum: args[1][0], col: args[1][1] }
if (this._lastHold && equals(this._lastHold, ev)) return
this._lastHold = ev
}
if (event == 'CursorMoved' || event == 'CursorMovedI') {
this._bufnr = args[0]
let cursor = {
bufnr: args[0],
lnum: args[1][0],
Expand Down

0 comments on commit c136a60

Please sign in to comment.