Comments (9)
Maybe <% tp.file.cursor() %>
should also do that, as it only makes sense to use in edit mode.
from templater.
Could be related to #1112
from templater.
I am experiencing this as well with same versions but macOS 13.4.1 (a).
It also happens when I try to create a periodic note from editing view.
edit: Sorry I might have misread the original issue,
<% tp.file.cursor() %>
No longer works for me
from templater.
I'd argue that this is expected and desired behavior. It would be weird if a user setup multiple cursors and suddenly they're all gone because they were accidentally in reading mode instead of editing mode.
Note
Example of multiple cursors.
Name: <% tp.file.cursor(0) %>
Status: <% tp.file.cursor(1) %>
I recommend switching to edit mode and run the Templater: Jump to next cursor location
command to jump to the cursor and remove it.
from templater.
True, for multiple cursors this would be weird. But even for a single cursor with <% tp.file.cursor(0) %>
this happens for me.
But maybe it is just me finding this weird. 😄
from templater.
I also have this issue.
When creating a new node from the calendar widget, and either of these conditions are pressent:
- No files are open
- Nne or more are open, but not in edit mode
Then <% tp.file.cursor() %>
is not executed.
I propose that when creating a new note and Templater is engaged, then it should switch to edit mode automatically.
from templater.
I don't think it's a good idea to switch the mode on the user. Part of the benefit of Templater is you can bind templates to a hotkey to quickly run a script on the current note to manipulate it, without having to be in edit mode. I know of users who stay in reading mode and run hotkeys to mark a note as reviewed before moving on to the next note.
I would be open to a contribution for a new Templater function in the file module or something that can switch the mode explicitly.
from templater.
I like that, should be easy enough to implement.
Even just making the change to have tp.file.cursor()
change the view to edit mode if you're in reading mode should resolve this issue, no need to add a new function to templater.
from templater.
In the meantime, one can add a user function following the doc.
Script above exporting the function:
function switch_to_editmode () {
/* Be sure to switch to edit mode first (live preview)
It is required so it can insert the template in existing file. */
const view = app.workspace.activeLeaf.getViewState()
view.state.mode = 'source'
view.state.source = false
app.workspace.activeLeaf.setViewState(view)
}
module.exports = switch_to_editmode;
Then you call it in your template:
<%*
/* Be sure to switch to edit mode first (live preview)
It is required so it can insert the template in existing file. */
tp.user.Switch_to_edit_mode();
// start of template construct
// insert your logic here
if (title.startsWith("Untitled")) {
title = await tp.system.prompt("What is the plugin name ?");
await tp.file.rename(title);
}
// and so on
%>
Further in the template, add this to jump to the cursor on any case. It is necessary if create a new note from the template where the focus is on the note title. You just press enter to validate it and the cursor jumps to the anchor.
# Description
<% tp.file.cursor(1) %><%* app.workspace.activeLeaf.view.editor?.focus(); %>
Source: https://forum.obsidian.md/t/easily-switch-between-source-mode-live-preview-preview/27151/25
from templater.
Related Issues (20)
- Link to a new file will trigger Templater in a specific folder HOT 2
- Feature request: allow for ordering which templater code is excuted first HOT 2
- Templater updates new file's last modified timestamp even if no templater code was run
- SImple syntax not displaying values correctly HOT 2
- Suggestion to Improve New Folder Template Addition Behavior in Templater Settings HOT 1
- Bug | tp.date.now() will incorrectly parse the last week of the year and first week of the next year HOT 2
- Random picture generator inoperable HOT 16
- First character of file path cut off in command palette if no templates folder set HOT 9
- Minify main.js HOT 1
- Add support for vanilla template variables like {{data}} for enhanced compatibility
- Using tp.file.rename doesn't rename current note but creates a new note instead HOT 1
- System Prompt in file order HOT 3
- First letter of every file cut off in search modal HOT 1
- template mis-applied when a note is created but not opened HOT 1
- generate_folder() has incorrect `relative` logic vs generate_path() HOT 1
- Syntax highlight on desktop causes the leading part of unordered list in table cell to disappear HOT 1
- Request: Zipped release for manual install
- Duplication bug when using Multiple Cursors
- Templater web requests not working on Obsidian mobile HOT 2
- Unable to create my own quote callout using tp.web.request - 400 error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from templater.