aboutsummaryrefslogtreecommitdiff
path: root/ext/js/dom
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-05-16 15:24:38 -0400
committerGitHub <noreply@github.com>2021-05-16 15:24:38 -0400
commit66d048832f2dc30e11e6be4c68beab23c7d8adef (patch)
tree9cb1d83faacf133f61c3a96156ea6de1541e5233 /ext/js/dom
parent41ee167dfdfcd794634e0459185a929e814b0493 (diff)
Sentence termination character mode (#1682)
* Change enableTerminationCharacters to terminationCharacterMode * Update settings * Update sentence extraction * Update tests * Add tests
Diffstat (limited to 'ext/js/dom')
-rw-r--r--ext/js/dom/document-util.js7
1 files changed, 4 insertions, 3 deletions
diff --git a/ext/js/dom/document-util.js b/ext/js/dom/document-util.js
index 8284ffa5..da4d3e61 100644
--- a/ext/js/dom/document-util.js
+++ b/ext/js/dom/document-util.js
@@ -69,6 +69,7 @@ class DocumentUtil {
* @param source The text source object, either `TextSourceRange` or `TextSourceElement`.
* @param layoutAwareScan Whether or not layout-aware scan mode should be used.
* @param extent The length of the sentence to extract.
+ * @param terminateAtNewlines Whether or not a sentence should be terminated at newline characters.
* @param terminatorMap A mapping of characters that terminate a sentence.
* Format:
* ```js
@@ -87,7 +88,7 @@ class DocumentUtil {
* ```
* @returns The sentence and the offset to the original source: `{sentence: string, offset: integer}`.
*/
- extractSentence(source, layoutAwareScan, extent, terminatorMap, forwardQuoteMap, backwardQuoteMap) {
+ extractSentence(source, layoutAwareScan, extent, terminateAtNewlines, terminatorMap, forwardQuoteMap, backwardQuoteMap) {
// Scan text
source = source.clone();
const startLength = source.setStartOffset(extent, layoutAwareScan);
@@ -102,7 +103,7 @@ class DocumentUtil {
let quoteStack = [];
for (; pos1 > 0; --pos1) {
const c = text[pos1 - 1];
- if (c === '\n') { break; }
+ if (c === '\n' && terminateAtNewlines) { break; }
if (quoteStack.length === 0) {
const terminatorInfo = terminatorMap.get(c);
@@ -133,7 +134,7 @@ class DocumentUtil {
quoteStack = [];
for (; pos2 < textLength; ++pos2) {
const c = text[pos2];
- if (c === '\n') { break; }
+ if (c === '\n' && terminateAtNewlines) { break; }
if (quoteStack.length === 0) {
const terminatorInfo = terminatorMap.get(c);