generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
change the time to register "create" event. support insert multi imgs at once. #24
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hey, thanks for contributing.
Following seems to allow multi drop and even saves a few
|
npm run dev
…________________________________
发件人: xRyul ***@***.***>
发送时间: 2023年10月18日 19:10
收件人: xRyul/obsidian-image-converter ***@***.***>
抄送: dotkt ***@***.***>; Author ***@***.***>
主题: Re: [xRyul/obsidian-image-converter] change the time to register "create" event. support insert multi imgs at once. (PR #24)
Hey, thanks for contributing.
* How do you compile it? ESlint throws quite a few errors.
* Please remove any variables, or console logs which are not being used.
Following seems to allow multi drop and even saves a few ms during load. Many thanks 🙏 although, going to have to test it further, especially with various SYNC methods
this.dropListener = () => {
userAction = true;
setTimeout(() => userAction = false, 10000);
};
this.app.workspace.onLayoutReady(() => {
document.addEventListener("paste", this.pasteListener);
document.addEventListener('drop', this.dropListener);
this.registerEvent(
this.app.vault.on('create', (file: TFile) => {
if (!(file instanceof TFile)) return;
if (isImage(file) && userAction) {
this.renameFile1(file);
}
// userAction = false; // uncommented to allow multi-drop
})
);
})
...
const currentLine = cursor.line;
function escapeRegExp(string: string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& 表示整个匹配的字符串
}
const findText = escapeRegExp(linkText);
const replaceText = newLinkText;
const docContent = editor.getValue();
const regex = new RegExp(findText, 'g');
const newContent = docContent.replace(regex, replaceText);
editor.setValue(newContent);
editor.setCursor({ line: currentLine, ch: 0 });
// Ensure the current line is in a visible position
editor.scrollIntoView({ from: { line: currentLine, ch: 0 }, to: { line: currentLine, ch: 0 } });
—
Reply to this email directly, view it on GitHub<#24 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AL3UF5R3VBTOSCQOJY5GDXTX762JPAVCNFSM6AAAAAA6AYLMJOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONRYGIZDIMJSGY>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
change the time to register "create" event. support insert multi imgs at once.