Created
January 8, 2022 04:07
-
-
Save GitMurf/c52dfef13162d88375975e4eefedf3a7 to your computer and use it in GitHub Desktop.
Revisions
-
GitMurf created this gist
Jan 8, 2022 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,58 @@ <%* //OPTIONS: TOP / BOTTOM const whereToWrite = "TOP"; //OPTIONS: COPY / MOVE const copyOrMove = "COPY"; //Find leaf next door const thisLeaf = app.workspace.activeLeaf; const thisFile = thisLeaf.view.file; let leafToUse = app.workspace.getAdjacentLeafInDirection(thisLeaf, "right"); if(!leafToUse){leafToUse = app.workspace.getAdjacentLeafInDirection(thisLeaf, "left");} if(!leafToUse){leafToUse = app.workspace.getAdjacentLeafInDirection(thisLeaf, "bottom");} if(!leafToUse){leafToUse = app.workspace.getAdjacentLeafInDirection(thisLeaf, "top");} if(leafToUse) { //Find selected text or text on current line const editor = app.workspace.activeLeaf.view.editor; if(editor.somethingSelected() === false) { const curLineNum = editor.getCursor().line; editor.setSelection({ line: curLineNum, ch: 0 }, { line: curLineNum, ch: editor.getLine(curLineNum).length }); } let curLineStr = editor.getSelection(); if(curLineStr) { curLineStr = curLineStr.trim(); const nextEditor = leafToUse.view.editor; const foundFile = leafToUse.view.file; let lineNo = 0; switch(whereToWrite.toUpperCase()) { case "TOP": lineNo = 0; const mdCache = app.metadataCache.getFileCache(foundFile); if(mdCache) { if(mdCache.frontmatter) { lineNo = mdCache.frontmatter.position.end.line; } } break; case "BOTTOM": lineNo = nextEditor.lastLine(); break; } const curText = nextEditor.getLine(lineNo); nextEditor.setLine(lineNo,`${curText}\n${curLineStr}`); nextEditor.setCursor(lineNo + 1); switch(copyOrMove.toUpperCase()) { case "COPY": tR = curLineStr; break; case "MOVE": tR = ""; break; } } } %>