generated from mirrors/plugin-sample-vite-svelte
Optimization
All checks were successful
Build on Push and create Release on Tag / build (push) Successful in 3m58s
All checks were successful
Build on Push and create Release on Tag / build (push) Successful in 3m58s
This commit is contained in:
parent
b7c81d1fa0
commit
68025b9a34
2 changed files with 32 additions and 22 deletions
|
|
@ -114,7 +114,8 @@ export default class SpellCheckPlugin extends Plugin {
|
||||||
|
|
||||||
if(settings.enabled) {
|
if(settings.enabled) {
|
||||||
await this.suggestions.storeBlocks(protyle, settings.language)
|
await this.suggestions.storeBlocks(protyle, settings.language)
|
||||||
void this.suggestions.forAllBlocksSuggest(true, true)
|
const useOnline = this.settingsUtil.get('online');
|
||||||
|
void this.suggestions.forAllBlocksSuggest(true, true, useOnline ? undefined : 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -66,12 +66,17 @@ export class SuggestionEngine {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public async forAllBlocksSuggest(suggest: boolean = false, render: boolean = true) {
|
public async forAllBlocksSuggest(suggest: boolean = false, render: boolean = true, concurrencyLimit: number = 1000) {
|
||||||
const blockPromises = Object.keys(this.blockStorage).map(async (blockID) => {
|
|
||||||
|
const blockIDs = Object.keys(this.blockStorage);
|
||||||
|
for (let i = 0; i < blockIDs.length; i += concurrencyLimit) {
|
||||||
|
|
||||||
|
const batch = blockIDs.slice(i, i + concurrencyLimit);
|
||||||
|
const blockPromises = batch.map(async (blockID) => {
|
||||||
if(!(blockID in this.blockStorage)) {
|
if(!(blockID in this.blockStorage)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if(suggest && this.blockStorage[blockID].suggestions == null) {
|
if(suggest === true && this.blockStorage[blockID].suggestions == null) {
|
||||||
await this.suggestForBlock(blockID)
|
await this.suggestForBlock(blockID)
|
||||||
}
|
}
|
||||||
if(render) {
|
if(render) {
|
||||||
|
|
@ -79,6 +84,11 @@ export class SuggestionEngine {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
await Promise.all(blockPromises);
|
await Promise.all(blockPromises);
|
||||||
|
// yield to the event loop to prevent UI freezing
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 1));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async suggestAndRender(blockID: string) {
|
public async suggestAndRender(blockID: string) {
|
||||||
|
|
@ -148,14 +158,13 @@ export class SuggestionEngine {
|
||||||
private shouldSuggest(blockID: string, block: StoredBlock, suggestion: Suggestion): boolean {
|
private shouldSuggest(blockID: string, block: StoredBlock, suggestion: Suggestion): boolean {
|
||||||
|
|
||||||
const element = block.protyle.fastGetBlockElement(blockID)
|
const element = block.protyle.fastGetBlockElement(blockID)
|
||||||
const eai = ProtyleHelper.getElementAtTextIndex(element, suggestion.offset + suggestion.length)
|
const eaiStart = ProtyleHelper.getElementAtTextIndex(element, suggestion.offset)
|
||||||
|
const eaiEnd = ProtyleHelper.getElementAtTextIndex(element, suggestion.offset + suggestion.length)
|
||||||
|
|
||||||
for(let blacklisted of SuggestionEngine.blacklisted) {
|
return !SuggestionEngine.blacklisted.some(blacklisted =>
|
||||||
if(eai instanceof Element && eai.matches(blacklisted)) {
|
(eaiStart instanceof Element && eaiStart.matches(blacklisted)) ||
|
||||||
return false
|
(eaiEnd instanceof Element && eaiEnd.matches(blacklisted))
|
||||||
}
|
);
|
||||||
}
|
|
||||||
return true
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -188,7 +197,7 @@ export class SuggestionEngine {
|
||||||
const offset = this.getAbsoluteOffsetInBlock(range, blockID)
|
const offset = this.getAbsoluteOffsetInBlock(range, blockID)
|
||||||
let suggNo = -1
|
let suggNo = -1
|
||||||
|
|
||||||
this.blockStorage[blockID].suggestions.forEach((suggestion, i) => {
|
this.blockStorage[blockID].suggestions?.forEach((suggestion, i) => {
|
||||||
if(offset >= suggestion.offset && offset <= suggestion.offset + suggestion.length) {
|
if(offset >= suggestion.offset && offset <= suggestion.offset + suggestion.length) {
|
||||||
suggNo = i
|
suggNo = i
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue