RickStrahl / Snippets-MarkdownMonster-Addin

A Snippet Expansion Manager for embedding templated text into Markdown Monster Markdown documents
https://markdownmonster.west-wind.com
5 stars 3 forks source link

Ability to position cursor after snippet addition #3

Closed gep13 closed 7 years ago

gep13 commented 7 years ago

After adding the snippet, my cursor is here:

image

Is it possible to define within the snippet where the cursor should go? Ideally, I would end up here:

image

After adding the snippet so that I can immediately add the tags for the post.

RickStrahl commented 7 years ago

Yup. ~ syntax like Visual Studio snippets :-) It's one of the things that's on my list. Requires dealing with the selection range that can be a bit tricky and requires some explicit code in the editor.js code.

RickStrahl commented 7 years ago

So added this in ad02ec150392dde9b2b90efab84d247edd6ffa72

@{
    var file = Path.GetFileNameWithoutExtension(
                                 Model.ActiveDocument.Filename);
    file = StringUtils.FromCamelCase(file);
    file = file.Replace("-"," ");
}---
Title: @file
Timestamp: @DateTime.Now.ToString("MMM dd, yyyy HH:mm")
Tags:
- ~
---

The ~ determines where the cursor goes if specified.

It's in 0.2, but this change also requires an update to MM 1.1.18

gep13 commented 7 years ago

Sweet! Will take this for a spin later.

gep13 commented 7 years ago

Just got this...

image

After updating to 1.1.18, and re-installing the addin.

RickStrahl commented 7 years ago

Hmmm... that looks like a different OLD version. 1.0.28. You should be on 1.1.18.

And yes the updated addin requires the newer build.

Can you send me your last error log entries that pertain to that error? I might be able to block off the code that won't run in older versions. I lost track :-)

RickStrahl commented 7 years ago

Ok installed older version and re-ran and was able to figure out what was not working - bracketed the new code so it should work now. Update the addin.

gep13 commented 7 years ago

I think I see the problem...

Looks like there is an issue with the mm.exe/bat:

image

If I run mm, I don't get version 1.1.18.

RickStrahl commented 7 years ago

Ah - yes. This was due to the switch to the 32 bit version. You probably didn't uninstall the old version when the switch came and Mm is probably still looking at the old \program files\ path.

To fix:

You should end up with only the new version and path pointing at \program files (x86)\Markdown Monster.

That was a sucky thing to have to do but there was no way around that. It was in the update notice and docs to do a full uninstall firs then reinstall, but of course nobody actually reads that :-)

gep13 commented 7 years ago

Yeah, that did it:

image

Yip, I never read that part, just did a choco upgrade. If this needs to happen again, you could add a chocolateyBeforeModify.ps1 script, to do a full uninstall of the application, if currently installed.

gep13 commented 7 years ago

@RickStrahl ok, now we are getting somewhere. I am running this:

image

and this:

image

And this is my snippet definition:

image

But after adding bfm I get this:

image

RickStrahl commented 7 years ago

Hmmm... that should work. I just installed 1.1.18 from Choco, unloaded the existing addin and reloaded it and it works for me. You did restart MM after installing the updated addin right? Since addins load in memory a restart is required.

FWIW, there are a bunch of updates coming to the Addin Manager and addin handling in general in the next update (1.1.20 most likely).

image

that will hopefully make updates a little less painful than they are right now.

gep13 commented 7 years ago

@RickStrahl yip, multiple restarts. I have this morning uninstalled all addins, and then re-installed them, but the same thing happens. I wondered if it was something to do with the fact that I was using the vim emulation layer for the editor, but turning the on/off didn't result in any difference either. The ~ was still output into the document, rather than replacing it with cursor.

I will try again once new MM is published.

RickStrahl commented 7 years ago

1.1.19 is out on the Web site (not on Choco yet). I can confirm with 1.1.19 and 0.2.3 installed the ~ is working for me in expansions.

RickStrahl commented 7 years ago

The fact that the ~ is still in the output is probably a dead giveaway, you're not running the latest addin as the ~ is replaced even before the cursor movement.

Is the addin showing up more than once in your Addin list? I fixed the naming to be consistent so it's possible that a new install will not remove the old one.

To fix manually:

gep13 commented 7 years ago

Nope, only showing up once in Addins list.

I have just cleared out the folders that you suggested. Updated to latest MM. Re-installed Snippets addin and still get the same thing. The ~ is still output, and cursor is not where it is expected to be 😢

image

image

RickStrahl commented 7 years ago

I mean on the toolbar. There's an icon - (pen in a box). Is that there more than once?

This one: image

gep13 commented 7 years ago

@RickStrahl thanks again! This is now resolved.

RickStrahl commented 7 years ago

Thanks for your help and persistance on this.