255 lines
6.8 KiB
JavaScript
255 lines
6.8 KiB
JavaScript
var Types = require("types.js");
|
|
|
|
|
|
/**
|
|
* Represents a buffer
|
|
* @class
|
|
* @param {InternalClient} client The vim client linked to the buffer
|
|
* @param {number} buffId Id of the buffer
|
|
*/
|
|
function Buffer (client, buffId) {
|
|
"use strict";
|
|
|
|
var typeNum = 0; //WARNING : check if this should be unique to a buffer
|
|
var serNum = 0; //WARNING : check if this should be unique to a buffer
|
|
|
|
/* COMMANDS */
|
|
|
|
/**
|
|
* Place an annotation
|
|
* @function
|
|
* @param {number} annoType Returned annoType by defineAnnoType
|
|
* @param {number|number[]} offset Position of the annotation
|
|
* @return {number} Serial number of the anno
|
|
*/
|
|
this.addAnno = function (annoType, off) {
|
|
serNum += 1;
|
|
client.sendCommand("addAnno", buffId, serNum, annoType,Types.position(off), 0 );
|
|
return serNum;
|
|
};
|
|
|
|
/**
|
|
* Close the buffer.
|
|
* @function
|
|
*/
|
|
this.close = function(){
|
|
client.sendCommand("close", buffId);
|
|
};
|
|
|
|
/**
|
|
* Define a type of annotation for this buffer
|
|
* @function
|
|
* @param {string} typeName Name that identifies this annotation type
|
|
* @param {string} glyphFile Name of icon file
|
|
* @param {string|number} fg Foreground color
|
|
* @param {string|number} bg Background color
|
|
* @return {number} Identifier of the annotation type
|
|
*/
|
|
this.defineAnnoType = function (typeName, glyphFile, fg, bg) {
|
|
typeNum += 1;
|
|
client.sendCommand("defineAnnoType", buffId, typeNum, Types.string(typeName), Types.string(""), Types.string(glyphFile), Types.color(fg), Types.color(bg));
|
|
return typeNum;
|
|
};
|
|
|
|
/**
|
|
* Mark the buffer to report changes with "insert" and "remove" events
|
|
* @function
|
|
*/
|
|
this.startDocumentListen = function () {
|
|
client.sendCommand("startDocumentListen", buffId);
|
|
};
|
|
|
|
|
|
/**
|
|
* Mark the buffer to stop reporting changes
|
|
* @function
|
|
*/
|
|
this.stopDocumentListen = function () {
|
|
client.sendCommand("stopDocumentListen", buffId);
|
|
};
|
|
|
|
/**
|
|
* Mark an area in the buffer as guarded
|
|
* @function
|
|
* @param {number|number[]} off Starting position
|
|
* @param {number} len Length of the area
|
|
*/
|
|
this.guard = function (off, len) {
|
|
client.sendCommand("guard",buffId, Types.position(off), len);
|
|
};
|
|
|
|
/**
|
|
* Tell Vim that the buffer is ready to be used and make it the current buffer
|
|
* Fire the BufReadPost autocommand event
|
|
* @function
|
|
*/
|
|
this.initDone = function () {
|
|
client.sendCommand("initdone", buffId);
|
|
};
|
|
|
|
|
|
/**
|
|
* Tell Vim an initial insert is done
|
|
* Trigger a read message being printed
|
|
* @function
|
|
*/
|
|
this.insertDone = function () {
|
|
client.sendCommand("insertDone", buffId);
|
|
};
|
|
|
|
|
|
/**
|
|
* Tell Vim that the buffer is owned by the controller
|
|
* @function
|
|
* @param isNetBeansBuffer
|
|
*/
|
|
this.netbeansBuffer = function (isNetBeansBuffer) {
|
|
client.sendCommand("netbeansBuffer", buffId, Types.bool(isNetBeansBuffer));
|
|
};
|
|
|
|
|
|
/**
|
|
* Removes a previously added annotation
|
|
* @function
|
|
* @param {number} serNum Identifier of the annotation to remove
|
|
*/
|
|
this.removeAnno = function (serNum) {
|
|
client.sendCommand("removeAnno",buffId,serNum);
|
|
};
|
|
|
|
/**
|
|
* Tell Vim to save the buffer
|
|
* Vim fire a setModified event when done
|
|
* @function
|
|
**/
|
|
this.save = function () {
|
|
client.sendCommand("save", buffId);
|
|
};
|
|
|
|
/**
|
|
* Tell Vim the buffer has been saved
|
|
* @function
|
|
*/
|
|
this.saveDone = function () {
|
|
client.sendCommand("saveDone", buffId);
|
|
};
|
|
|
|
|
|
/**
|
|
* Set Vim cursor position and set the buffer as current buffer
|
|
* @function
|
|
* @param {number|number[]} off Position of the cursor
|
|
*/
|
|
this.setDot = function (off) {
|
|
client.sendCommand("setDot", buffId, Types.position(off));
|
|
};
|
|
|
|
/**
|
|
* Set the name of the buffer.
|
|
* It does not read the file content
|
|
* @function
|
|
* @param {string} pathName Name of the buffer
|
|
*/
|
|
this.setFullName = function (pathName) {
|
|
client.sendCommand("setFullName", buffId, Types.string(pathName));
|
|
};
|
|
|
|
/**
|
|
* Toggle the buffer modified mark
|
|
* @function
|
|
* @param {bool} modified Value of the modified flag
|
|
*/
|
|
this.setModified = function (modified) {
|
|
client.sendCommand("setModified", buffId, Types.bool(modified));
|
|
};
|
|
|
|
/**
|
|
* Update a buffer modification time
|
|
* @function
|
|
* @param {number} time Modification time to set
|
|
*/
|
|
this.setModtime = function (time) {
|
|
client.sendCommand("setModtime", buffId, time);
|
|
};
|
|
|
|
/**
|
|
* Mark the buffer as readonly
|
|
* @function
|
|
*/
|
|
this.setReadOnly = function () {
|
|
client.sendCommand("setReadOnly", buffId);
|
|
};
|
|
|
|
/**
|
|
* Set the title of the function (used by controller only)
|
|
* @function
|
|
* @param {string} name Name of the buffer
|
|
*/
|
|
this.setTitle = function (name) {
|
|
client.sendCommand("setTitle", buffId, Types.string(name));
|
|
};
|
|
|
|
/**
|
|
* Goto the buffer
|
|
* @function
|
|
*/
|
|
this.setVisible = function () {
|
|
client.sendCommand("setVisible", buffId, Types.bool(true));
|
|
};
|
|
|
|
/**
|
|
* Display a balloon containing the text (GVim only)
|
|
* @function
|
|
* @param {string} text Text to show
|
|
*/
|
|
this.showBalloon = function (text) {
|
|
client.sendCommand("showBalloon", buffId,Types.string(text));
|
|
};
|
|
|
|
/**
|
|
* Ungard the text
|
|
* @function
|
|
* @param {number|number[]} off Start position of the text to unguard
|
|
* @param {number} len Length of the text to unguard
|
|
*/
|
|
this.unguard = function (off, len) {
|
|
client.sendCommand("unguard", buffId, Types.position(off), len);
|
|
};
|
|
|
|
this.editFile = function (pathName){
|
|
client.sendCommand("editFile", buffId, Types.string(pathName));
|
|
};
|
|
|
|
|
|
/* FUNCTIONS */
|
|
|
|
this.getCursor = function (callback) {
|
|
client.callFunction("getCursor", buffId, callback);
|
|
};
|
|
|
|
this.getLength = function (callback) {
|
|
client.callFunction("getLength", buffId, callback);
|
|
};
|
|
|
|
this.getAnno = function (serNum, callback) {
|
|
client.callFunction("getAnno", buffId, serNum, callback);
|
|
};
|
|
|
|
this.getModified = function (callback) {
|
|
client.callFunction("getModified", buffId, callback);
|
|
};
|
|
|
|
this.getText = function (callback) {
|
|
client.callFunction("getText", buffId, callback);
|
|
};
|
|
|
|
this.insert = function (off, text, callback){
|
|
client.callFunction("insert", buffId, Types.position(off), Types.string(text), callback);
|
|
};
|
|
|
|
this.remove = function (off, length, callback) {
|
|
client.callFunction("remove", buffId, Types.position(off), length, callback);
|
|
};
|
|
}
|
|
|