UNPKG

@chemzqm/neovim

Version:

NodeJS client API for vim9 and neovim

118 lines (117 loc) 4.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Window = void 0; const constants_1 = require("../utils/constants"); const Base_1 = require("./Base"); class Window extends Base_1.BaseApi { constructor() { super(...arguments); this.prefix = 'nvim_win_'; } /** * The windowid that not change within a Vim session */ get id() { return this.data; } setBuffer(buffer) { return this.request(`${this.prefix}set_buf`, [buffer]); } /** Retrieves a scoped option depending on type of `this` */ getOption(name) { if (constants_1.isCocNvim) return this.request(`nvim_get_option_value`, [name, { win: this.id }], true); return super.getOption(name); } setOption(name, value, isNotify) { if (constants_1.isCocNvim) return this[isNotify ? 'notify' : 'request'](`nvim_set_option_value`, [name, value, { win: this.id }], true); return this[isNotify ? 'notify' : 'request'](`${this.prefix}set_option`, [name, value]); } /** Get current buffer of window */ get buffer() { return this.request(`${this.prefix}get_buf`, []); } /** Get the Tabpage that contains the window */ get tabpage() { return this.request(`${this.prefix}get_tabpage`, []); } /** Get cursor position */ get cursor() { return this.request(`${this.prefix}get_cursor`, []); } setCursor(pos, isNotify = false) { let method = isNotify ? 'notify' : 'request'; return this[method](`${this.prefix}set_cursor`, [pos]); } /** Get window height by number of rows */ get height() { return this.request(`${this.prefix}get_height`, []); } setHeight(height, isNotify = false) { let method = isNotify ? 'notify' : 'request'; return this[method](`${this.prefix}set_height`, [height]); } /** Get window width by number of columns */ get width() { return this.request(`${this.prefix}get_width`, []); } setWidth(width, isNotify = false) { let method = isNotify ? 'notify' : 'request'; return this[method](`${this.prefix}set_width`, [width]); } /** Get window position */ get position() { return this.request(`${this.prefix}get_position`, []); } /** 0-indexed, on-screen window position(row) in display cells. */ get row() { return this.request(`${this.prefix}get_position`, []).then(position => position[0]); } /** 0-indexed, on-screen window position(col) in display cells. */ get col() { return this.request(`${this.prefix}get_position`, []).then(position => position[1]); } /** Is window valid */ get valid() { return this.request(`${this.prefix}is_valid`, []); } /** Get window number */ get number() { return this.request(`${this.prefix}get_number`, []); } setConfig(options, isNotify) { let method = isNotify ? 'notify' : 'request'; return this[method](`${this.prefix}set_config`, [options]); } getConfig() { return this.request(`${this.prefix}get_config`, []); } close(force, isNotify) { if (isNotify) { this.notify(`${this.prefix}close`, [force]); return null; } return this.request(`${this.prefix}close`, [force]); } highlightRanges(hlGroup, ranges, priority = 10, isNotify) { if (isNotify) { this.client.call('coc#highlight#match_ranges', [this.id, 0, ranges, hlGroup, priority], true); return undefined; } return this.client.call('coc#highlight#match_ranges', [this.id, 0, ranges, hlGroup, priority]); } /** * Clear match by highlight group. */ clearMatchGroup(hlGroup) { this.client.call('coc#window#clear_match_group', [this.id, hlGroup], true); } /** * Clear match by match ids. */ clearMatches(ids) { this.client.call('coc#window#clear_matches', [this.id, ids], true); } } exports.Window = Window;