Skip to content

Commit

Permalink
refactor(folding): getBoundingClientRect()
Browse files Browse the repository at this point in the history
  • Loading branch information
bhsd-harry committed Nov 30, 2024
1 parent 2286be6 commit ccfc002
Show file tree
Hide file tree
Showing 12 changed files with 10 additions and 15 deletions.
Binary file added assets/autocomplete.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/folding.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/hover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/link.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/lint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/navigation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/outline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/rename.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/signature.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 8 additions & 12 deletions server/src/folding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ async function provide(
symbol ? 'heading' : 'heading,table,template,magic-word',
);
for (const token of tokens) {
const index = token.getAbsoluteIndex(),
{top} = root.posFromIndex(index)!;
const {top, height} = token.getBoundingClientRect();
if (token.type === 'heading') {
const {level, firstChild} = token;
if (symbol) {
Expand Down Expand Up @@ -58,17 +57,14 @@ async function provide(
});
}
}
levels[level - 1] = top + String(token.firstChild).split('\n').length - 1; // 从标题的最后一行开始折叠
}
} else if (!symbol) {
const {length} = String(token).split('\n');
if (length > 2) {
ranges.push({
startLine: top, // 从表格或模板的第一行开始折叠
endLine: top + length - 2,
kind: FoldingRangeKind.Region,
});
levels[level - 1] = top + token.firstChild.offsetHeight - 1; // 从标题的最后一行开始折叠
}
} else if (!symbol && height > 2) {
ranges.push({
startLine: top, // 从表格或模板的第一行开始折叠
endLine: top + height - 2,
kind: FoldingRangeKind.Region,
});
}
}
if (!symbol) {
Expand Down
5 changes: 2 additions & 3 deletions server/src/links.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Parser from 'wikilint';
import {plainTypes, createRange} from './util';
import {plainTypes, createNodeRange} from './util';
import {parse} from './tasks';
import type {Token, AttributeToken, TokenTypes} from 'wikilint';
import type {DocumentLink, TextDocumentIdentifier} from 'vscode-languageserver/node';
Expand Down Expand Up @@ -55,8 +55,7 @@ export const provideLinks = async ({uri}: TextDocumentIdentifier, path: string):
target = `https:${target}`;
}
new URL(target); // eslint-disable-line no-new
const from = token.getAbsoluteIndex();
return [{range: createRange(root, from, from + String(token).length), target}];
return [{range: createNodeRange(root, token), target}];
} catch {
return [];
}
Expand Down

0 comments on commit ccfc002

Please sign in to comment.