Code Monkey home page Code Monkey logo

Comments (9)

davidolrik avatar davidolrik commented on June 20, 2024 1

Maybe <% tp.file.cursor() %> should also do that, as it only makes sense to use in edit mode.

from templater.

RonMcKay avatar RonMcKay commented on June 20, 2024

Could be related to #1112

from templater.

spenserpothier avatar spenserpothier commented on June 20, 2024

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.

Zachatoo avatar Zachatoo commented on June 20, 2024

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.

RonMcKay avatar RonMcKay commented on June 20, 2024

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.

davidolrik avatar davidolrik commented on June 20, 2024

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.

Zachatoo avatar Zachatoo commented on June 20, 2024

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.

Zachatoo avatar Zachatoo commented on June 20, 2024

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.

Fred-Vatin avatar Fred-Vatin commented on June 20, 2024

In the meantime, one can add a user function following the doc.
image

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.