3 Commits
6 changed files with 54 additions and 39 deletions

No files matched your search

-28
View File
@@ -1,28 +0,0 @@
name: Node.js build
on:
push:
branches: ["**"]
pull_request:
branches: ["**"]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x, 22.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- run: npm ci
- run: npm run build --if-present
- run: npm run lint
+12
View File
@@ -3,6 +3,18 @@
All notable changes to this project are documented in this file. All notable changes to this project are documented in this file.
Format loosely follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). Format loosely follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
## [1.2.1] - 2026-11-11
### Fixed
- **Toggle Heading (strip formatting) left the cursor before the new marker on an
empty line.** Running *Toggle Heading - H1…H6 (strip formatting)* on an empty line
produced `|### ` instead of `### |`: the line was rewritten with `setLine`, which
maps a caret at column 0 to before the inserted text. The line replacement and the
cursor position are now set in a single transaction; the cursor keeps its position
relative to the line's text, also accounting for removed bold/italic markers.
(`src/ToggleHeading.ts`)
## [1.2.0] - 2026-10-08 ## [1.2.0] - 2026-10-08
### Added ### Added
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"id": "bindthem", "id": "bindthem",
"name": "BindThem", "name": "BindThem",
"version": "1.2.0", "version": "1.2.1",
"minAppVersion": "0.15.0", "minAppVersion": "0.15.0",
"description": "Enhanced editor shortcuts and formatting tools. Combines smart text wrapping (bold, italic, code, etc.), directional copy/move, heading toggles (H1-H6), line operations, case transformation, multi-cursor support, and file utilities into one unified plugin.", "description": "Enhanced editor shortcuts and formatting tools. Combines smart text wrapping (bold, italic, code, etc.), directional copy/move, heading toggles (H1-H6), line operations, case transformation, multi-cursor support, and file utilities into one unified plugin.",
"author": "Olivier Legendre", "author": "Olivier Legendre",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "bindthem", "name": "bindthem",
"version": "1.2.0", "version": "1.2.1",
"description": "A merged plugin combining obsidian-tweaks, obsidian-editor-shortcuts, and heading-toggler functionalities.", "description": "A merged plugin combining obsidian-tweaks, obsidian-editor-shortcuts, and heading-toggler functionalities.",
"main": "main.js", "main": "main.js",
"type": "module", "type": "module",
+38 -8
View File
@@ -121,20 +121,50 @@ export class ToggleHeading {
let content = line let content = line
let currentLevel = 0 let currentLevel = 0
let oldPrefixLength = 0
if (match) { if (match) {
currentLevel = match[1].length currentLevel = match[1].length
content = match[2] content = match[2]
oldPrefixLength = line.length - content.length
} }
// Strip bold and italic formatting // Cursor offset within the content (a caret inside the old marker
content = content // counts as the start of the content)
.replace(/(\*\*|__)(.*?)\1/g, '$2') let contentCursor = Math.max(0, cursor.ch - oldPrefixLength)
.replace(/(\*|_)(.*?)\1/g, '$2')
editor.setLine( // Strip bold and italic formatting, shifting the cursor offset left
cursor.line, // by the number of marker characters removed before it
currentLevel === level ? content : '#'.repeat(level) + ' ' + content const strip = (text: string, regex: RegExp): string =>
) text.replace(regex, (whole: string, marker: string, inner: string, offset: number) => {
const closeStart = offset + marker.length + inner.length
if (contentCursor >= closeStart + marker.length) {
contentCursor -= 2 * marker.length
} else if (contentCursor > closeStart) {
contentCursor = closeStart - marker.length
} else if (contentCursor >= offset + marker.length) {
contentCursor -= marker.length
} else if (contentCursor > offset) {
contentCursor = offset
}
return inner
})
content = strip(content, /(\*\*|__)(.*?)\1/g)
content = strip(content, /(\*|_)(.*?)\1/g)
const newPrefix = currentLevel === level ? '' : '#'.repeat(level) + ' '
// Replace the line and place the cursor in one transaction: a bare
// setLine maps a caret at ch 0 to before the inserted `#… ` prefix
editor.transaction({
changes: [{
from: { line: cursor.line, ch: 0 },
to: { line: cursor.line, ch: line.length },
text: newPrefix + content,
}],
selection: {
from: { line: cursor.line, ch: newPrefix.length + contentCursor },
},
}, 'ToggleHeadingStrip' + level.toString())
} }
} }
+2 -1
View File
@@ -1,5 +1,6 @@
{ {
"1.0.0": "0.15.0", "1.0.0": "0.15.0",
"1.1.0": "0.15.0", "1.1.0": "0.15.0",
"1.2.0": "0.15.0" "1.2.0": "0.15.0",
"1.2.1": "0.15.0"
} }