Skip to content

Commit

Permalink
Move isWhitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
toasted-nutbread committed Feb 2, 2024
1 parent 89faa7e commit 75a7c8c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
8 changes: 0 additions & 8 deletions ext/js/data/sandbox/string-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,3 @@ export function readCodePointsBackward(text, position, count) {
}
return result;
}

/**
* @param {string} string
* @returns {boolean}
*/
export function isWhitespace(string) {
return string.trim().length === 0;
}
17 changes: 12 additions & 5 deletions ext/js/dom/text-source-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import {isWhitespace} from '../data/sandbox/string-util.js';
import {DocumentUtil} from './document-util.js';
import {DOMTextScanner} from './dom-text-scanner.js';
import {TextSourceElement} from './text-source-element.js';
Expand Down Expand Up @@ -169,8 +168,8 @@ export class TextSourceGenerator {
}

// Trim whitespace
for (; cursorStart < startLength && isWhitespace(text[cursorStart]); ++cursorStart) { /* NOP */ }
for (; cursorEnd > textEndAnchor && isWhitespace(text[cursorEnd - 1]); --cursorEnd) { /* NOP */ }
for (; cursorStart < startLength && this._isWhitespace(text[cursorStart]); ++cursorStart) { /* NOP */ }
for (; cursorEnd > textEndAnchor && this._isWhitespace(text[cursorEnd - 1]); --cursorEnd) { /* NOP */ }

// Result
return {
Expand Down Expand Up @@ -371,7 +370,7 @@ export class TextSourceGenerator {
const {node, offset, content} = new DOMTextScanner(nodePre, offsetPre, true, false).seek(1);
range.setEnd(node, offset);

if (!isWhitespace(content) && DocumentUtil.isPointInAnyRect(x, y, range.getClientRects())) {
if (!this._isWhitespace(content) && DocumentUtil.isPointInAnyRect(x, y, range.getClientRects())) {
return true;
}
} finally {
Expand All @@ -382,7 +381,7 @@ export class TextSourceGenerator {
const {node, offset, content} = new DOMTextScanner(startContainer, range.startOffset, true, false).seek(-1);
range.setStart(node, offset);

if (!isWhitespace(content) && DocumentUtil.isPointInAnyRect(x, y, range.getClientRects())) {
if (!this._isWhitespace(content) && DocumentUtil.isPointInAnyRect(x, y, range.getClientRects())) {
// This purposefully leaves the starting offset as modified and sets the range length to 0.
range.setEnd(node, offset);
return true;
Expand Down Expand Up @@ -636,4 +635,12 @@ export class TextSourceGenerator {
_isElementUserSelectAll(element) {
return getComputedStyle(element).userSelect === 'all';
}

/**
* @param {string} string
* @returns {boolean}
*/
_isWhitespace(string) {
return string.trim().length === 0;
}
}

0 comments on commit 75a7c8c

Please sign in to comment.