Skip to content

Commit

Permalink
fix: make eachTokenForScreenRows a free function
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jan 2, 2021
1 parent 5e23805 commit a296f48
Showing 1 changed file with 29 additions and 28 deletions.
57 changes: 29 additions & 28 deletions lib/mixins/canvas-drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,33 +393,6 @@ export default class CanvasDrawer extends Mixin {
renderData.context.fill()
}

/**
* Returns an array of tokens by line.
*
* @param {number} startRow The start row
* @param {number} endRow The end row
* @return {Array<Array>} An array of tokens by line
* @access private
*/
eachTokenForScreenRows (startRow, endRow, callback) {
const editor = this.minimap.getTextEditor()
const invisibleRegExp = getInvisibleRegExp(editor)
endRow = Math.min(endRow, editor.getScreenLineCount())

for (let row = startRow; row < endRow; row++) {
const editorTokensForScreenRow = editor.tokensForScreenRow(row)
const numToken = editorTokensForScreenRow.length
const numTokenToRender = Math.min(numToken, this.maxTokensInOneLine)
for (let iToken = 0; iToken < numTokenToRender; iToken++) {
const token = editorTokensForScreenRow[iToken]
callback(row, {
text: token.text.replace(invisibleRegExp, ' '),
scopes: token.scopes
})
}
}
}

/**
* Draws lines on the corresponding layer.
*
Expand All @@ -445,7 +418,7 @@ export default class CanvasDrawer extends Mixin {

let lastLine, x
let y = (offsetRow * lineHeight) - lineHeight
this.eachTokenForScreenRows(firstRow, lastRow, (line, token) => {
eachTokenForScreenRows(firstRow, lastRow, this.minimap.getTextEditor(), this.maxTokensInOneLine, (line, token) => {
if (lastLine !== line) {
x = 0
y += lineHeight
Expand Down Expand Up @@ -711,6 +684,34 @@ export default class CanvasDrawer extends Mixin {
// ## ## ## ## ## ## ## ## ##
// ######## ## ## ## ## ### ###

/**
* Returns an array of tokens by line.
*
* @param {number} startRow The start row
* @param {number} endRow The end row
* @param {TextEditor} editor
* @param {number} maxTokensInOneLine the maximum number of tokens to render in one line
* @return {Array<Array>} An array of tokens by line
* @access private
*/
function eachTokenForScreenRows (startRow, endRow, editor, maxTokensInOneLine, callback) {
const invisibleRegExp = getInvisibleRegExp(editor)
endRow = Math.min(endRow, editor.getScreenLineCount())

for (let row = startRow; row < endRow; row++) {
const editorTokensForScreenRow = editor.tokensForScreenRow(row)
const numToken = editorTokensForScreenRow.length
const numTokenToRender = Math.min(numToken, maxTokensInOneLine)
for (let iToken = 0; iToken < numTokenToRender; iToken++) {
const token = editorTokensForScreenRow[iToken]
callback(row, {
text: token.text.replace(invisibleRegExp, ' '),
scopes: token.scopes
})
}
}
}

/**
* Returns the regexp to replace invisibles substitution characters
* in editor lines.
Expand Down

0 comments on commit a296f48

Please sign in to comment.