ryu1kn / vscode-text-marker

Visual Studio Code Extension. Select text in your code and mark all matches. The marking colour is configurable
https://marketplace.visualstudio.com/items?itemName=ryu1kn.text-marker
MIT License
87 stars 17 forks source link

Add option to update highlight from textmarker.savedHighlights without reloading editor #35

Open jsve opened 5 years ago

jsve commented 5 years ago

Thanks for a great plugin! Really useful in my current workflow!

Being able to set and save highlights for each workspace is great (in settings.json under textmarker.savedHighlights), however it is a bit difficult to set up manually. To see the changes I need to reload the entire vs-code window / editor. It would be great to have the option to reload the config and apply highlights though a command instead!

ryu1kn commented 5 years ago

Hi @jsve , that makes total sense! Thanks for the suggestion! 👍

IntoCpp commented 4 years ago

I'd like to add my support for this request. I've been looking a long time for this plug-in. A big thanks. I change my reg-ex many times per hour to isolate class names, members, exceptions and so on,so this would be great.

ryu1kn commented 4 years ago

Hi @IntoCpp , thanks for the encouraging comment.

Actually, I wonder if we've already solved this issue. You can edit existing highlight by right clicking the highlight and select Update Highlight. Once you become happy with your highlights, you can issue Save All Highlights command to save all them.

IntoCpp commented 4 years ago

Thank you for the quick response. "Update Highlight" menu does not appear to work for me. My test: 1) Open the user "settings.json" in VS-Code (the gloab/all-projects setting file) 2) In an existing "pattern" section (to compare with a working case) add a text to highlight. Example: I added "test_new_red" to my existing 'red-text' regex, I can see "Error:" already highlighted:

    // My text-marker plug-in: - Saved REGEX highlighters.
    "textmarker.savedHighlights": [
        {
            "pattern": 
            {
              "type": "regex",
              "expression": "Error:|test_new_red", // added 'test_new_red'
              "ignoreCase": true,
              "wholeMatch": true
            },
            "color": "red"
         },
     ]

3) Save the config file (keep it open). New text is not highlighted. 4) Right-click in file -> "Update Highlight".

5) Close VS-Code 6) Open VS-Code: The text is now highlighted.

Thanks for your attention in this issue. Not a big priority :)

ryu1kn commented 4 years ago

Ah I see. I was under the impression that users would not directly edit textmarker.savedHighlights except when they tweak it, as getting a regex right in one-go is hard (at least, for me).

  • textmarker.savedHighlights

    List of highlights that will get applied when opening editor. This value is typically set/updated by "Save All Highlights" command.

So the flow I add regex patterns are:

  1. Select Highlight Text Using Regex and type a pattern that should work.
  2. If it turns out that the pattern isn't right, right click the highlight and run Update Highlight, and select Update RegExp Pattern.
  3. Repeat the above step till I get it right.
  4. Once I'm satisfied the pattern, run Save All Highlights to persist it.
  5. Start from Step 1 to add another pattern.

Now I noticed that depending on the pattern in Step 1, it may not highlight anything and I cannot use Update Highlight... Perhaps I could change Update Highlight to let you select patterns when it is invoked NOT on a highlight. Do you think it works for you?

IntoCpp commented 4 years ago

Oh! I never used the command palette that much before. It takes some practice, but it gets the job done. :) Still, when facing complex regex with extended options (like mentioned in #48) a manual edition of the settings would be easier. I would replace all reg-ex and extended options commands with a simple "open config.json file" inside VSCode (already exists:"ctrl-shift-p:os json"). Maybe add a command to reload the options from the file. Also: When we run "Save All Highlights" to persist, any manual change in the settings.json (since VSCode was open) is lost. That may be a +point for a better handling of direct-edition of the settings.json file.

It's your call if you want to add this or not. The command-palette may be enough for 99% of users.

Finally: No need to bother with "it may not highlight anything and I cannot use Update Highlight... ", it's a minor annoyance that can be easily worked-around. Building complex reg-ex you usually start with a simple "working case" and build on it. (I use regex101.com).

Thank you again, and a very nice day to you.

Edit: Added Open Settings (JSON) via command palette)