Skip to content

Commit

Permalink
Move collapse button of the code indent to the right of the line numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
lijyze committed Aug 9, 2022
1 parent b900737 commit f38eb8e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-advanced-codeblock",
"name": "Advanced Codeblock",
"version": "1.1.1",
"version": "1.1.2",
"minAppVersion": "0.12.0",
"description": "Give additioinal features to code blocks.",
"author": "Lijyze",
Expand Down
18 changes: 11 additions & 7 deletions src/CM6Extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const livePreviewCM6Extension = ViewPlugin.fromClass(class {
showLineNumbers: false,
highlightLines: null,
}
let idx = 1;
let startLineNum: number;

for (const {from, to} of view.visibleRanges) {
try {
Expand All @@ -68,9 +68,11 @@ export const livePreviewCM6Extension = ViewPlugin.fromClass(class {

// reset data when found codeblock begin line.
if (isCodeblockBegin) {
idx = 1;
const codeblockParams = view.state.doc.lineAt(from).text.match(paramRegex).slice(1);
const startLine = view.state.doc.lineAt(from);
const codeblockParams = startLine.text.match(paramRegex).slice(1);
const highlightParam = codeblockParams.find((param) => braceSurroundingRegex.test(param))?.slice(1, -1);

startLineNum = startLine.number;
codeblockInfo.showLineNumbers = false;
codeblockInfo.highlightLines = null;

Expand All @@ -89,17 +91,21 @@ export const livePreviewCM6Extension = ViewPlugin.fromClass(class {
return [+line];
});
}

if (!isCodeblockLine) return ;

const currentLineNum = view.state.doc.lineAt(from).number;

if (codeblockInfo.showLineNumbers) {
const deco = Decoration.widget({
widget: new LineNumberWidget(idx)
widget: new LineNumberWidget(currentLineNum - startLineNum),
side: -10000
});
builder.add(from, from, deco);
}

if (codeblockInfo.highlightLines) {
if (codeblockInfo.highlightLines.includes(idx)) {
if (codeblockInfo.highlightLines.includes(currentLineNum - startLineNum)) {
const line = view.state.doc.lineAt(from);
const deco = Decoration.line({
attributes: {class: 'live-preview-codeblock-highlight'}
Expand All @@ -115,8 +121,6 @@ export const livePreviewCM6Extension = ViewPlugin.fromClass(class {
builder.add(line.from, line.from, deco);
}
}

idx++;
}
})
} catch (error) {
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"1.0.2": "0.12.0",
"1.0.3": "0.12.0",
"1.1.0": "0.12.0",
"1.1.1": "0.12.1"
"1.1.1": "0.12.0",
"1.1.2": "0.12.0"
}

0 comments on commit f38eb8e

Please sign in to comment.