From a296f4880b54dc65abc0ece57a249ec078d1a7ee Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sat, 2 Jan 2021 03:21:09 -0600 Subject: [PATCH] fix: make eachTokenForScreenRows a free function --- lib/mixins/canvas-drawer.js | 57 +++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/lib/mixins/canvas-drawer.js b/lib/mixins/canvas-drawer.js index e128b3ec..ed01c6ff 100644 --- a/lib/mixins/canvas-drawer.js +++ b/lib/mixins/canvas-drawer.js @@ -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} 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. * @@ -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 @@ -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} 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.