1. // 牙叔教程 简单易懂
  2. function sleep(milliseconds) {
  3. return new Promise((resolve) => setTimeout(resolve, milliseconds));
  4. }
  5. async function jump_to_next_cursor_location(params) {
  6. let activeFile = await params.app.workspace.getActiveFile();
  7. if (!activeFile) {
  8. new Notice("Notice: No active file.");
  9. return;
  10. }
  11. let fileContent = await params.app.vault.cachedRead(activeFile);
  12. let rowCount = fileContent.split("\n").length;
  13. let lastLine = fileContent.split("\n")[rowCount - 1];
  14. let lastLineLength = lastLine.length;
  15. let columnCount = lastLineLength;
  16. let cmEditor = params.app.workspace.activeLeaf.view.editor;
  17. let cursorLocation = cmEditor.getCursor();
  18. let newCursorLocation = {
  19. line: rowCount - 1,
  20. ch: columnCount,
  21. };
  22. console.log("newCursorLocation =");
  23. console.log(newCursorLocation);
  24. // let tagspos = params.app.workspace.activeLeaf.view.data.search("tags:");
  25. // let posLine = params.app.workspace.activeLeaf.view.editor.offsetToPos(tagspos);
  26. // posLine.ch += tagspos + 1;
  27. // cmEditor.focus();
  28. // cmEditor.setCursor(posLine);
  29. await cmEditor.setCursor(newCursorLocation);
  30. }
  31. // let cmEditor = params.app.workspace.activeLeaf.view.editor;
  32. // let curCursor = cmEditor.getCursor();
  33. // cmEditor.setCursor({ line: 9999, ch: 9999 });
  34. module.exports = async (params) => {
  35. console.log(params);
  36. // 获取当前活动文件
  37. let activeFile = await params.app.workspace.getActiveFile();
  38. if (!activeFile) {
  39. new Notice("Notice: No active file.");
  40. return;
  41. }
  42. let fileContent = await params.app.vault.cachedRead(activeFile);
  43. let content = "# 公众号: 牙叔教程";
  44. let newFileContent = `${fileContent}${content}`;
  45. // 修改文件内容
  46. await params.app.vault.modify(activeFile, newFileContent);
  47. await jump_to_next_cursor_location(params);
  48. await sleep(1000);
  49. for (var i = 1; i < 11; i++) {
  50. let fileContent = await params.app.vault.cachedRead(activeFile);
  51. let content = "\n" + i;
  52. let newFileContent = `${fileContent}${content}`;
  53. // 修改文件内容
  54. await params.app.vault.modify(activeFile, newFileContent);
  55. await jump_to_next_cursor_location(params);
  56. await sleep(1000);
  57. }
  58. new Notice("Notice: printNumber Finished!");
  59. console.log("Finished!");
  60. };

名人名言

思路是最重要的, 其他的百度, bing, stackoverflow, github, 安卓文档, autojs文档, 最后才是群里问问
—- 牙叔教程

声明

部分内容来自网络
本教程仅用于学习, 禁止用于其他用途

bilibili

牙叔教程

微信公众号 牙叔教程

修改光标位置 - 图1

QQ群

747748653
修改光标位置 - 图2