Code Monkey home page Code Monkey logo

Comments (4)

Zachatoo avatar Zachatoo commented on September 24, 2024 2

I did some research into this, and I don't think this is feasible to implement at the moment. The current implementation uses a Codemirror transaction to set the selection. This does not work with the new properties UI because it's not part of the editor for the purpose of transactions, the properties input boxes are divs that are contenteditable. We could maybe conditionally use browser APIs instead of Codemirror APIs, but that feels brittle.

If any Obsidian API experts have input on a way to accomplish this that isn't brittle, I would love to know about it.

Here's an example of what a browser API solution would look like, for reference.

function setCursorPosition(el, pos) {
  var range = document.createRange();
  var sel = window.getSelection();
  
  range.setStart(el, pos);
  range.collapse(true);
  
  sel.removeAllRanges();
  sel.addRange(range);
}

// Assuming we have figured out which property value and what position within that contenteditable div for that property value
const propertyIndex = 0;
const characterIndex = 19;
setCursorPosition(this.app.workspace.activeEditor.metadataEditor.rendered.at(propertyIndex).valueEl.childNodes.at(0).childNodes.at(0), characterIndex);

from templater.

tprotopopescu avatar tprotopopescu commented on September 24, 2024

It is not just in tags; I have the same problem in the body of a note. <% tp.file.cursor(1) %> works in preview mode if the template is at the beginning of a line. It does not work if the template is inserted in the middle of a line, the cursor is placed at the beginning of the text to be inserted instead. It works as expected in source mode.

Probably related to #1089

from templater.

Zachatoo avatar Zachatoo commented on September 24, 2024

tp.file.cursor() will need to be updated to work in the properties widget. That is the reason it doesn't work.

from templater.

homosco avatar homosco commented on September 24, 2024

Adding to this because it's probably related: If I'm in editing a property and jump to the next tp.file.cursor() position, the templater tag ("<% tp.file.cursor() %>") ist removed but the cursor isn't moved but stays in properties forcing me to use the mouse to move out of Properties.

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.