Author Topic: an Unusual highlighting need  (Read 1727 times)

Offline 999hippo

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
an Unusual highlighting need
« on: August 16, 2013, 02:44:39 am »
I have a simple plugin: a cursor change event in the active-view triggers a function.

I would like the function to now:

      change the highlighting of the 3 characters left and right of the current cursor to RED.

(I need to see quickly and clearly where things have been affected by the other aspect of the function)

I am too new to sort this out in any reasonable period of time, so am truly grateful for any help.

Offline alex

  • Developer
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2170
  • Karma: +37/-3
    • View Profile
    • HippoEDIT
Re: an Unusual highlighting need
« Reply #1 on: August 17, 2013, 12:30:15 pm »
Here is an example:
Code: Javascript
  1. // create the highlighting style, remember, it is alive whole editor session
  2. var styleHighlight = new Style("my_highlighting", "Highlighting", "My Highlighting Style");
  3. styleHighlight.ForeColor = "#FF0000";
  4. //styleHighlight.BackColor = "#FF0000";
  5.  
  6. // get current cursor position
  7. var posAbs = ActiveDocument.TextToAbsolute(ActiveView.Position);
  8.  
  9. // create range including two characters before and two after
  10. var posStart = ActiveDocument.AbsoluteToText(posAbs - 2);
  11. var posEnd = ActiveDocument.AbsoluteToText(posAbs + 2);
  12. var rangeHighlight = new Range(posStart.Line, posStart.Pos, posEnd.Line, posEnd.Pos);
  13.  
  14. // highlight range with our style
  15. ActiveDocument.AddStyleRange(rangeHighlight, styleHighlight);
  16.  
  17. // remove our highlighting
  18. sleep(3000);
  19. ActiveDocument.RemoveStyleRanges(null, styleHighlight);

I have also uploaded new version of scripting.hejs test, which also contains some examples.

During preparation of example I have noticed some glitches (as style can not be updated any more after initial creation in session) which I will try to fix in new updates.
If you find something that from your point of view works not as designed, please inform me, and I will check, if it is really like this and can be fixed/optimized.

BR, Alex.

Offline 999hippo

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: an Unusual highlighting need
« Reply #2 on: August 17, 2013, 01:27:54 pm »
BRILLIANT!

It is not a complex little block of code, but would have cost me a couple days to sort out, so I appreciate it.

I now have my first plugin working EXACTLY as I want it, doing something I couldn't discover any other existing program capable of doing. (I'd post the plugin, but its extremely specific for a wierd peculiar need, so shouln't be of much value to anyone else).

I first tried HippoEDIT back when v1.34 was offered on giveawayoftheday. I've alsways liked it, but, have also always had a whole arsenal of text editors, so didn't always turn to it. But when I saw the addition of this scripting hosting, I knew this COULD solve my problem. Thanks to your fast response, it's solved. I still have 28 days left on my trial install of v1.5, but I just happily BOUGHT IT!!!

Thanks again for the assistance.

Offline alex

  • Developer
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2170
  • Karma: +37/-3
    • View Profile
    • HippoEDIT
Re: an Unusual highlighting need
« Reply #3 on: August 17, 2013, 03:16:40 pm »
No problem.

And thanks for feedback and registration. The license key is on the way.

Publish your plugin on forum, and we will check if it can be turned to something useful for all. Nevertheless if I see the code, I can suggest something, knowing HE internals.

BR, Alex.

 

Related Topics

  Subject / Started by Replies Last post
1 Replies
2279 Views
Last post February 23, 2009, 04:09:01 pm
by alex
10 Replies
5874 Views
Last post January 21, 2012, 03:21:37 am
by alex
13 Replies
9112 Views
Last post May 09, 2010, 10:31:57 pm
by alex
1 Replies
1620 Views
Last post June 22, 2011, 02:14:50 am
by alex
5 Replies
2384 Views
Last post January 21, 2012, 06:37:41 pm
by alex