Skip to content

Commit

Permalink
fix: word extension detection sometimes bad
Browse files Browse the repository at this point in the history
  • Loading branch information
JeppeKlitgaard committed Jun 13, 2021
1 parent fea6b66 commit 83df905
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Move selection does not support going across lines. This seems unnecessary and
is really messy to implement.
### Better Toggles

The default toggles in Obsidian can be quite wonky and do not always
The default toggles in Obsidian can be a bit wonky at times and do not always
work well. The toggles implemented here should always return to the
same state when toggled twice.

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-tweaks",
"name": "Obsidian Tweaks",
"version": "0.2.1",
"version": "0.2.2",
"minAppVersion": "0.12.3",
"description": "A small plugin that implements some sorely missed features.",
"author": "Jeppe Klitgaard",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-tweaks",
"version": "0.2.1",
"version": "0.2.2",
"description": "A small plugin that implements some sorely missed features.",
"main": "main.js",
"scripts": {
Expand Down
13 changes: 10 additions & 3 deletions src/BetterFormatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,16 @@ export class BetterFormatting {
{line: wordEnd.line, ch: wordEnd.ch + symbolEnd.length},
)

if (preWordStart === symbolStart && postWordStart === symbolEnd) {
wordStart = {line: wordStart.line, ch: wordStart.ch - symbolStart.length}
wordEnd = {line: wordEnd.line, ch: wordEnd.ch + symbolEnd.length}
if (
(preWordStart === symbolStart || textToWrap.startsWith(symbolStart)) &&
(postWordStart === symbolEnd || textToWrap.endsWith(symbolEnd))
) {
// Calculate which offsets to use depending on which of the cases above
let startOffset = textToWrap.startsWith(symbolStart) ? 0 : -2
let endOffset = textToWrap.endsWith(symbolEnd) ? 0 : 2

wordStart = {line: wordStart.line, ch: wordStart.ch + startOffset}
wordEnd = {line: wordEnd.line, ch: wordEnd.ch + endOffset}

// Update textToWrap
textToWrap = editor.getRange(wordStart, wordEnd)
Expand Down
1 change: 1 addition & 0 deletions versions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"0.2.2": "0.12.3",
"0.2.1": "0.12.3",
"0.2.0": "0.12.3",
"0.1.1": "0.12.3",
Expand Down

0 comments on commit 83df905

Please sign in to comment.