-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement very basic find API #704
Merged
Merged
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
8d12881
Very basic find implementation
Tyriar 280b698
More work on findNext
Tyriar d3f5a06
Fix search scrolling up
Tyriar 7d8f698
Add findPrevious
Tyriar f88dcd1
Expose API on Terminal
Tyriar b957130
Consolidate translateBufferLineToString functions
Tyriar 5360277
Merge remote-tracking branch 'origin/master' into 553_find_api
Tyriar 528f06b
Remove log
Tyriar 39151e4
Merge branch 'master' into 553_find_api
Tyriar 6854def
Use case-insensitive search by default
Tyriar f93b24a
Merge branch 'master' into 553_find_api
Tyriar 1938145
Get find working as an addon
Tyriar baccca8
Merge branch 'master' into 553_find_api
Tyriar 11de0d0
Merge remote-tracking branch 'ups/master' into 553_find_api
Tyriar 80f7a37
Point to search addon properly
Tyriar 3c0e142
Fix sourcemaps
Tyriar fab039d
Rearrange module loader to work with browserify
Tyriar 4b0cf2f
jsdoc
Tyriar 2564592
Change case of search addon files
Tyriar c13b86a
Add find to demo
Tyriar c62923f
Change case of browserify-addons files
Tyriar 73970ec
Fix casing of search.js
Tyriar 4c0e7b2
Merge remote-tracking branch 'ups/master' into 553_find_api
Tyriar af58643
Merge branch 'master' into 553_find_api
Tyriar 43b47ab
Merge branch 'master' into 553_find_api
Tyriar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import { CircularList } from './utils/CircularList'; | |
import { EventEmitter } from './EventEmitter'; | ||
import { ITerminal } from './Interfaces'; | ||
import { SelectionModel } from './SelectionModel'; | ||
import { translateBufferLineToString } from './utils/BufferLine'; | ||
|
||
/** | ||
* The number of pixels the mouse needs to be above or below the viewport in | ||
|
@@ -181,6 +182,9 @@ export class SelectionManager extends EventEmitter { | |
this.clearSelection(); | ||
} | ||
|
||
public get selectionStart(): [number, number] { return this._model.finalSelectionStart; } | ||
public get selectionEnd(): [number, number] { return this._model.finalSelectionEnd; } | ||
|
||
/** | ||
* Gets whether there is an active text selection. | ||
*/ | ||
|
@@ -206,12 +210,12 @@ export class SelectionManager extends EventEmitter { | |
// Get first row | ||
const startRowEndCol = start[1] === end[1] ? end[0] : null; | ||
let result: string[] = []; | ||
result.push(this._translateBufferLineToString(this._buffer.get(start[1]), true, start[0], startRowEndCol)); | ||
result.push(translateBufferLineToString(this._buffer.get(start[1]), true, start[0], startRowEndCol)); | ||
|
||
// Get middle rows | ||
for (let i = start[1] + 1; i <= end[1] - 1; i++) { | ||
const bufferLine = this._buffer.get(i); | ||
const lineText = this._translateBufferLineToString(bufferLine, true); | ||
const lineText = translateBufferLineToString(bufferLine, true); | ||
if (bufferLine.isWrapped) { | ||
result[result.length - 1] += lineText; | ||
} else { | ||
|
@@ -222,7 +226,7 @@ export class SelectionManager extends EventEmitter { | |
// Get final row | ||
if (start[1] !== end[1]) { | ||
const bufferLine = this._buffer.get(end[1]); | ||
const lineText = this._translateBufferLineToString(bufferLine, true, 0, end[0]); | ||
const lineText = translateBufferLineToString(bufferLine, true, 0, end[0]); | ||
if (bufferLine.isWrapped) { | ||
result[result.length - 1] += lineText; | ||
} else { | ||
|
@@ -248,55 +252,6 @@ export class SelectionManager extends EventEmitter { | |
this.refresh(); | ||
} | ||
|
||
/** | ||
* Translates a buffer line to a string, with optional start and end columns. | ||
* Wide characters will count as two columns in the resulting string. This | ||
* function is useful for getting the actual text underneath the raw selection | ||
* position. | ||
* @param line The line being translated. | ||
* @param trimRight Whether to trim whitespace to the right. | ||
* @param startCol The column to start at. | ||
* @param endCol The column to end at. | ||
*/ | ||
private _translateBufferLineToString(line: any, trimRight: boolean, startCol: number = 0, endCol: number = null): string { | ||
// TODO: This function should live in a buffer or buffer line class | ||
|
||
// Get full line | ||
let lineString = ''; | ||
let widthAdjustedStartCol = startCol; | ||
let widthAdjustedEndCol = endCol; | ||
for (let i = 0; i < line.length; i++) { | ||
const char = line[i]; | ||
lineString += char[LINE_DATA_CHAR_INDEX]; | ||
// Adjust start and end cols for wide characters if they affect their | ||
// column indexes | ||
if (char[LINE_DATA_WIDTH_INDEX] === 0) { | ||
if (startCol >= i) { | ||
widthAdjustedStartCol--; | ||
} | ||
if (endCol >= i) { | ||
widthAdjustedEndCol--; | ||
} | ||
} | ||
} | ||
|
||
// Calculate the final end col by trimming whitespace on the right of the | ||
// line if needed. | ||
let finalEndCol = widthAdjustedEndCol || line.length; | ||
if (trimRight) { | ||
const rightWhitespaceIndex = lineString.search(/\s+$/); | ||
if (rightWhitespaceIndex !== -1) { | ||
finalEndCol = Math.min(finalEndCol, rightWhitespaceIndex); | ||
} | ||
// Return the empty string if only trimmed whitespace is selected | ||
if (finalEndCol <= widthAdjustedStartCol) { | ||
return ''; | ||
} | ||
} | ||
|
||
return lineString.substring(widthAdjustedStartCol, finalEndCol); | ||
} | ||
|
||
/** | ||
* Queues a refresh, redrawing the selection on the next opportunity. | ||
* @param isNewSelection Whether the selection should be registered as a new | ||
|
@@ -611,13 +566,21 @@ export class SelectionManager extends EventEmitter { | |
return charIndex; | ||
} | ||
|
||
public setSelection(col: number, row: number, length: number): void { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you document this with JSDoc please? |
||
this._model.clearSelection(); | ||
this._removeMouseDownListeners(); | ||
this._model.selectionStart = [col, row]; | ||
this._model.selectionStartLength = length; | ||
this.refresh(); | ||
} | ||
|
||
/** | ||
* Gets positional information for the word at the coordinated specified. | ||
* @param coords The coordinates to get the word at. | ||
*/ | ||
private _getWordAt(coords: [number, number]): IWordPosition { | ||
const bufferLine = this._buffer.get(coords[1]); | ||
const line = this._translateBufferLineToString(bufferLine, false); | ||
const line = translateBufferLineToString(bufferLine, false); | ||
|
||
// Get actual index, taking into consideration wide characters | ||
let endIndex = this._convertViewportColToCharacterIndex(bufferLine, coords); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you document these with JSDoc please?