Skip to content

Commit

Permalink
fix: 🐛 selectNextInstance used regexQuery.length to extend selectionR…
Browse files Browse the repository at this point in the history
…ange.head

Use regexMatch.length instead!
  • Loading branch information
SkepticMystic committed Oct 24, 2021
1 parent e988f13 commit d339183
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,11 @@ If you prefer bullet points to not have an extra line between them, use this to

- 3
```

#### Select Sentences

```re
/\b.*?\. /
```

Select the shortest string between a word boundary `\b` and a fullstop `\.`
25 changes: 13 additions & 12 deletions main.js

Large diffs are not rendered by default.

21 changes: 10 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,20 +200,16 @@ export default class ACPlugin extends Plugin {
const content = editor.getValue();

let toSelect = currSelection;
if (existingQ) {
toSelect = existingQ.query;
}
console.log({ toSelect });
let nextI;
if (existingQ) {
const offset = editor.posToOffset(editor.getCursor());

const regex = createRegex(existingQ);
const matches = [...content.matchAll(regex)];
nextI = matches.find((match) => match.index >= offset)?.index;
const nextMatch = matches.find((match) => match.index >= offset);
nextI = nextMatch?.index;
toSelect = nextMatch?.[0] ?? currSelection;
console.log({ matches, nextI });

// nextI = content.indexOf(existingQ.query, offset);
} else {
nextI = content.indexOf(toSelect, headOffset);
}
Expand All @@ -225,10 +221,13 @@ export default class ACPlugin extends Plugin {
to: editorSelection.head,
});
} else {
const regex = createRegex(existingQ);
const matches = [...content.matchAll(regex)];
const loopedI = matches[0].index;
console.log({ matches, loopedI });
let loopedI: number;
if (existingQ) {
const regex = createRegex(existingQ);
loopedI = [...content.matchAll(regex)]?.[0]?.index;
} else {
loopedI = content.indexOf(toSelect);
}

if (loopedI > -1) {
const editorSelection = this.createSelection(editor, loopedI, toSelect);
Expand Down

0 comments on commit d339183

Please sign in to comment.