Get find working as an addon
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import { SearchHelper } from './SearchHelper';
|
||||
|
||||
declare var exports: any;
|
||||
declare var module: any;
|
||||
declare var define: any;
|
||||
declare var require: any;
|
||||
|
||||
(function (addon) {
|
||||
if ('Terminal' in window) {
|
||||
/*
|
||||
* Plain browser environment
|
||||
*/
|
||||
addon((<any>window).Terminal);
|
||||
} else if (typeof define == 'function') {
|
||||
/*
|
||||
* Require.js is available
|
||||
*/
|
||||
define(['../../xterm'], addon);
|
||||
} else if (typeof exports === 'object' && typeof module === 'object') {
|
||||
/*
|
||||
* CommonJS environment
|
||||
*/
|
||||
var xterm = '../../xterm'; // Put in a variable do it's not pulled in by browserify
|
||||
module.exports = addon(require(xterm));
|
||||
}
|
||||
})((Terminal: any) => {
|
||||
/**
|
||||
* Find the next instance of the term, then scroll to and select it. If it
|
||||
* doesn't exist, do nothing.
|
||||
* @param term The term to search for.
|
||||
* @return Whether a result was found.
|
||||
*/
|
||||
Terminal.prototype.findNext = function(term: string): boolean {
|
||||
if (!this._searchHelper) {
|
||||
this.searchHelper = new SearchHelper(this, Terminal.translateBufferLineToString);
|
||||
}
|
||||
return (<SearchHelper>this.searchHelper).findNext(term);
|
||||
};
|
||||
|
||||
/**
|
||||
* Find the previous instance of the term, then scroll to and select it. If it
|
||||
* doesn't exist, do nothing.
|
||||
* @param term The term to search for.
|
||||
* @return Whether a result was found.
|
||||
*/
|
||||
Terminal.prototype.findPrevious = function(term: string): boolean {
|
||||
if (!this._searchHelper) {
|
||||
this.searchHelper = new SearchHelper(this, Terminal.translateBufferLineToString);
|
||||
}
|
||||
return (<SearchHelper>this.searchHelper).findPrevious(term);
|
||||
};
|
||||
});
|
||||
@@ -2,8 +2,8 @@
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import { ITerminal } from './Interfaces';
|
||||
import { translateBufferLineToString } from './utils/BufferLine';
|
||||
// import { ITerminal } from '../../Interfaces';
|
||||
// import { translateBufferLineToString } from '../../utils/BufferLine';
|
||||
|
||||
interface ISearchResult {
|
||||
term: string;
|
||||
@@ -12,7 +12,7 @@ interface ISearchResult {
|
||||
}
|
||||
|
||||
export class SearchHelper {
|
||||
constructor(private _terminal: ITerminal) {
|
||||
constructor(private _terminal: any, private _translateBufferLineToString: any) {
|
||||
// TODO: Search for multiple instances on 1 line
|
||||
// TODO: Don't use the actual selection, instead use a "find selection" so multiple instances can be highlighted
|
||||
// TODO: Highlight other instances in the viewport
|
||||
@@ -103,7 +103,7 @@ export class SearchHelper {
|
||||
|
||||
private _findInLine(term: string, y: number): ISearchResult {
|
||||
const bufferLine = this._terminal.lines.get(y);
|
||||
const lowerStringLine = translateBufferLineToString(bufferLine, true).toLowerCase();
|
||||
const lowerStringLine = this._translateBufferLineToString(bufferLine, true).toLowerCase();
|
||||
const lowerTerm = term.toLowerCase();
|
||||
const searchIndex = lowerStringLine.indexOf(lowerTerm);
|
||||
if (searchIndex >= 0) {
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"rootDir": ".",
|
||||
"outDir": "./c",
|
||||
"sourceMap": true,
|
||||
"removeComments": true
|
||||
}
|
||||
}
|
||||
+2
-23
@@ -21,12 +21,12 @@ import { Parser } from './Parser';
|
||||
import { Renderer } from './Renderer';
|
||||
import { Linkifier } from './Linkifier';
|
||||
import { SelectionManager } from './SelectionManager';
|
||||
import { SearchHelper } from './SearchHelper';
|
||||
import { CharMeasure } from './utils/CharMeasure';
|
||||
import * as Browser from './utils/Browser';
|
||||
import * as Mouse from './utils/Mouse';
|
||||
import { CHARSETS } from './Charsets';
|
||||
import { getRawByteCoords } from './utils/Mouse';
|
||||
import { translateBufferLineToString } from './utils/BufferLine';
|
||||
|
||||
/**
|
||||
* Terminal Emulation References:
|
||||
@@ -224,7 +224,6 @@ function Terminal(options) {
|
||||
this.renderer = this.renderer || null;
|
||||
this.selectionManager = this.selectionManager || null;
|
||||
this.linkifier = this.linkifier || new Linkifier();
|
||||
this.searchHelper = this.searchHelper || null;
|
||||
|
||||
// user input states
|
||||
this.writeBuffer = [];
|
||||
@@ -708,7 +707,6 @@ Terminal.prototype.open = function(parent, focus) {
|
||||
this.selectionManager.on('refresh', data => this.renderer.refreshSelection(data.start, data.end));
|
||||
this.on('scroll', () => this.selectionManager.refresh());
|
||||
this.viewportElement.addEventListener('scroll', () => this.selectionManager.refresh());
|
||||
this.searchHelper = new SearchHelper(this);;
|
||||
|
||||
// Setup loop that draws to screen
|
||||
this.refresh(0, this.rows - 1);
|
||||
@@ -1408,26 +1406,6 @@ Terminal.prototype.selectAll = function() {
|
||||
this.selectionManager.selectAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the next instance of the term, then scroll to and select it. If it
|
||||
* doesn't exist, do nothing.
|
||||
* @param term The term to search for.
|
||||
* @return Whether a result was found.
|
||||
*/
|
||||
Terminal.prototype.findNext = function(term) {
|
||||
return this.searchHelper.findNext(term);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the previous instance of the term, then scroll to and select it. If it
|
||||
* doesn't exist, do nothing.
|
||||
* @param term The term to search for.
|
||||
* @return Whether a result was found.
|
||||
*/
|
||||
Terminal.prototype.findPrevious = function(term) {
|
||||
return this.searchHelper.findPrevious(term);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a keydown event
|
||||
* Key Resources:
|
||||
@@ -2408,6 +2386,7 @@ function keys(obj) {
|
||||
* Expose
|
||||
*/
|
||||
|
||||
Terminal.translateBufferLineToString = translateBufferLineToString;
|
||||
Terminal.EventEmitter = EventEmitter;
|
||||
Terminal.inherits = inherits;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user