Skip to content

Commit 8b4cdc8

Browse files
Fix: fixes CodeMirror word finder discrimination
CodeMirror does not consider some symbols like asterisks as part of a word. We on the other hand believe that all symbols are created equal (except whitespaces and spaces of other colours).
1 parent dca00ed commit 8b4cdc8

File tree

5 files changed

+38
-3
lines changed

5 files changed

+38
-3
lines changed

RELEASE.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Release
2+
3+
1. Update `versions.json`
4+
2. Update `manifest.json`
5+
3. Update `pacakge.json`
6+
4. Commit
7+
5. Tag (`git tag x.y.z`)
8+
6. Push (`git push`)
9+
7. Make release on GitHub
10+
1. manifest.json
11+
2. styles.css
12+
3. main.js
13+
4. versions.json

manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "obsidian-tweaks",
33
"name": "Obsidian Tweaks",
4-
"version": "0.2.0",
4+
"version": "0.2.1",
55
"minAppVersion": "0.12.3",
66
"description": "A small plugin that implements some sorely missed features.",
77
"author": "Jeppe Klitgaard",

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "obsidian-tweaks",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "A small plugin that implements some sorely missed features.",
55
"main": "main.js",
66
"scripts": {

src/BetterFormatting.ts

+22-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export class BetterFormatting {
3434

3535
let textToWrap = editor.getRange(wordStart, wordEnd)
3636

37+
// Fix for inconsistent toggling
3738
if (textToWrap.trim() === "") {
3839
wordStart = anchor
3940
wordEnd = anchor
@@ -55,14 +56,34 @@ export class BetterFormatting {
5556

5657
// Update textToWrap again
5758
textToWrap = editor.getRange(wordStart, wordEnd)
58-
5959
}
6060

6161
let alreadyWrapped = (
6262
textToWrap.startsWith(symbolStart) &&
6363
textToWrap.endsWith(symbolEnd)
6464
)
6565

66+
// Fix for not all symbols considered part of word
67+
if (!alreadyWrapped) {
68+
let preWordStart = editor.getRange(
69+
{line: wordStart.line, ch: wordStart.ch - symbolStart.length},
70+
{line: wordStart.line, ch: wordStart.ch},
71+
)
72+
let postWordStart = editor.getRange(
73+
{line: wordEnd.line, ch: wordEnd.ch},
74+
{line: wordEnd.line, ch: wordEnd.ch + symbolEnd.length},
75+
)
76+
77+
if (preWordStart === symbolStart && postWordStart === symbolEnd) {
78+
wordStart = {line: wordStart.line, ch: wordStart.ch - symbolStart.length}
79+
wordEnd = {line: wordEnd.line, ch: wordEnd.ch + symbolEnd.length}
80+
81+
// Update textToWrap
82+
textToWrap = editor.getRange(wordStart, wordEnd)
83+
alreadyWrapped = true
84+
}
85+
}
86+
6687
let newText: string
6788
if (alreadyWrapped) {
6889
newText = textToWrap.substring(symbolStart.length, textToWrap.length - symbolEnd.length)

versions.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"0.2.1": "0.12.3",
23
"0.2.0": "0.12.3",
34
"0.1.1": "0.12.3",
45
"0.1.0": "0.12.3"

0 commit comments

Comments
 (0)