open a .tex file via macro, file path problem #3187
-
I came across this discussion on GitHub (#1403) where I found a potential solution for opening and closing files without relying on the mouse. However, I encountered an issue where it only works if I manually enter the complete file path. Ideally, I would like to have a local solution that allows me to open files within the same directory without having to specify the entire path each time. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
%SCRIPT |
Beta Was this translation helpful? Give feedback.
%SCRIPT
// trigger = open((\s+\S+)+)\s+end
// This script is used to open a file in the same folder, even if it is in a subfolder.
// Usage: To open a file, use the following trigger command:
// open subfolder1 subfolder2 ... file-name end
// Spaces in the names of subfolders and the file name should be replaced with colons (":").
var currentFilePath = editor.fileName();
var directoryPath = currentFilePath.substring(0, currentFilePath.lastIndexOf("/"));
var triggerText = triggerMatches[1].trim();
var words = triggerText.split(/\s+/);
var fileName = words.pop().replace(/:/g, ' ');
var folderPath = words.join('/').replace(/:/g, ' ');
var filePath = directoryPath + '/' + folderPath + '/' + f…