Recent

Author Topic: MarkupManager/Markup remove  (Read 2332 times)

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 267
MarkupManager/Markup remove
« on: July 08, 2022, 04:54:13 pm »
since this code seems OK
Code: Pascal  [Select][+][-]
  1. SynEdit1.MarkupManager.Markup[i]
  2.  

One would expect there would be something like
Code: Pascal  [Select][+][-]
  1. for i := 0 to SynEdit1.MarkupManager.Markup.Count - 1
  2. begin
  3.   //remove/free/destroy markup
  4. end
  5.  

so one could remove all markups.

There isn't any Markup.Count as far as I can see.

How to remove all Markups from MarkupManager , if any there at all ?
« Last Edit: July 08, 2022, 05:20:22 pm by BubikolRamios »
lazarus 3.2-fpc-3.2.2-win32/win64

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9857
  • Debugger - SynEdit - and more
    • wiki
Re: MarkupManager/Markup remove
« Reply #1 on: July 08, 2022, 05:22:44 pm »
What about
Code: Pascal  [Select][+][-]
  1. TSynEditMarkupManager.RemoveMarkUp
and
Code: Pascal  [Select][+][-]
  1. TSynEditMarkupManager.Count: Integer;

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 267
Re: MarkupManager/Markup remove
« Reply #2 on: July 08, 2022, 05:38:38 pm »
I already had this, i seems to be 6 (no idea where it gets that), then goes to exception
Code: Pascal  [Select][+][-]
  1.  for i := 0 to SynEdit1.MarkupManager.Count - 1  do
  2.  begin
  3.      SynEdit1.MarkupManager.RemoveMarkUp( SynEdit1.MarkupManager.Markup[i]);
  4.   end;
  5.          
  6.  

unclear what MarkupManager.Count means, count of MarkupManager or Markup within it ?
lazarus 3.2-fpc-3.2.2-win32/win64

BlueIcaro

  • Hero Member
  • *****
  • Posts: 792
    • Blog personal
Re: MarkupManager/Markup remove
« Reply #3 on: July 08, 2022, 05:46:24 pm »
Hi, try this
Code: [Select]
  for I := SynEdit1.MarkupManager.Count - 1 downto 0 do
    SynEdit1.MarkupManager.RemoveMarkUp(SynEdit1.MarkupManager.Markup[i]); 

You should remove any list starting from the end

/BlueIcaro

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9857
  • Debugger - SynEdit - and more
    • wiki
Re: MarkupManager/Markup remove
« Reply #4 on: July 08, 2022, 06:33:00 pm »
if you remove markup[0], then count goes down one, and all markups move one index down....

But your "for" loop will
- increase "i" to 1 => so you are skipping the element that now moved to 0
- no read the count again. For loops only read the "from" and "to" once. And then loop with those values that they read. Even if the expressions change.

alpine

  • Hero Member
  • *****
  • Posts: 1061
Re: MarkupManager/Markup remove
« Reply #5 on: July 08, 2022, 06:47:57 pm »
I already had this, i seems to be 6 (no idea where it gets that), then goes to exception
Code: Pascal  [Select][+][-]
  1.  for i := 0 to SynEdit1.MarkupManager.Count - 1  do
  2.  begin
  3.      SynEdit1.MarkupManager.RemoveMarkUp( SynEdit1.MarkupManager.Markup[i]);
  4.   end;
  5.          
  6.  

unclear what MarkupManager.Count means, count of MarkupManager or Markup within it ?

After Martin_fr explained it, you should consider one of:
  • That BlueIcaro suggested
Or (replace i with 0 in the 3-rd line:
Code: Pascal  [Select][+][-]
  1. for i := 0 to SynEdit1.MarkupManager.Count - 1  do
  2.  begin
  3.      SynEdit1.MarkupManager.RemoveMarkUp( SynEdit1.MarkupManager.Markup[0]);
  4.   end;
Or even:
Code: Pascal  [Select][+][-]
  1. while SynEdit1.MarkupManager.Count > 0  do
  2.  begin
  3.      SynEdit1.MarkupManager.RemoveMarkUp( SynEdit1.MarkupManager.Markup[0]);
  4.   end;

Edit: corrected Count > 1 with Count > 0.

« Last Edit: July 08, 2022, 06:56:26 pm by y.ivanov »
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

wp

  • Hero Member
  • *****
  • Posts: 11912
Re: MarkupManager/Markup remove
« Reply #6 on: July 08, 2022, 06:52:01 pm »
Code: Pascal  [Select][+][-]
  1. while SynEdit1.MarkupManager.Count > 1  do
  2.  begin
  3.      SynEdit1.MarkupManager.RemoveMarkUp( SynEdit1.MarkupManager.Markup[0]);
  4.   end;
No, this will keep one item. Correct: "while ... > 0 do"

alpine

  • Hero Member
  • *****
  • Posts: 1061
Re: MarkupManager/Markup remove
« Reply #7 on: July 08, 2022, 07:05:23 pm »
*snip*
No, this will keep one item. Correct: "while ... > 0 do"
Quite right! Stupid me. That's because of my previous remarks to jamie :(
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9857
  • Debugger - SynEdit - and more
    • wiki
Re: MarkupManager/Markup remove
« Reply #8 on: July 08, 2022, 09:25:31 pm »
unclear what MarkupManager.Count means, count of MarkupManager or Markup within it ?

The same as with any similar "list" object.

TStringList has
Code: Pascal  [Select][+][-]
  1. AStringList.Strings[n];
  2. AStringList.Count
but not AStringList.Strings.Count

OK, MarkupManager is called ...Manager and not ...List.

And it gets confusing, because often the "strings" in TStringList (or in any TStrings) is omitted.
e.g.
  SynEdit.Lines[1]
is actually
  SynEdit.Lines.Strings[1]

And
  SynEdit.Lines.Count
is actually the count of Strings in the Lines object.
There is just ONE "lines object"

It's just a clever trick in the name giving, that "strings" (as the property is named) for the human observer means lines.
And that therefore "lines.count", gives you the count of "lines", but not the count of "lines" objects.

SCNR, a bit of fun with the naming. ;)

---
All that aside, yes SynEdit.MarkupManager.MarkupCount would have made it more clear. But well now it is just "Count".


BubikolRamios

  • Sr. Member
  • ****
  • Posts: 267
Re: MarkupManager/Markup remove
« Reply #9 on: July 09, 2022, 01:30:33 am »
Thanks. Do tell how to actually clear painted text in synedit, painted by previous markup.
i.e.
1.have markup set and text gets painted
2.remove all markups
3.set new markup

Now typing text that matches new markup, into synedit , is painted correctly, old erased markup is 'ignored'
But previously painted text, by old markup is still there, painted as it was before.


Code: Pascal  [Select][+][-]
  1. //something on click, repeatedly, meanwhile changing markup searchTerm via some textbox
  2.  
  3.  //This thing obviously has something in defult as it goes in loop a couple of times
  4. // without me adding any markup anytime before
  5.  while SynEdit1.MarkupManager.Count > 0  do
  6.  begin
  7.    SynEdit1.MarkupManager.RemoveMarkUp( SynEdit1.MarkupManager.Markup[0]);
  8.  end;
  9.  
  10.  
  11.   //create new highlighter
  12.   YourMarkup := TSynEditMarkupHighlightAllMulti.create(SynEdit1);
  13.  
  14.   SynEdit.MarkupManager.AddMarkUp(YourMarkup);
  15.   YourMarkup.MarkupInfo.Background := ATStringProc_HtmlColor.SHtmlColorToColor('#fff000');
  16.   YourMarkup.MarkupInfo.Foreground := clBlack;
  17.   YourMarkup.MarkupInfo.Style := [fsUnderline];
  18.  
  19.    
  20.   YourMarkup.AddSearchTerm('new markup from some textbox');
  21.  
  22.  
  23.  
  24.  
« Last Edit: July 09, 2022, 01:33:21 am by BubikolRamios »
lazarus 3.2-fpc-3.2.2-win32/win64

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9857
  • Debugger - SynEdit - and more
    • wiki
Re: MarkupManager/Markup remove
« Reply #10 on: July 09, 2022, 01:42:20 am »
Code: Pascal  [Select][+][-]
  1. SynEdit.Invalidate;
To cause a repaint.

That should probably better happen automatically.
Feel free to report that on the bug tracker "removing markup does not invalidate SynEdit"
(assuming that it works when you call invalidate from your code)

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 267
Re: MarkupManager/Markup remove
« Reply #11 on: July 10, 2022, 10:00:44 pm »
Code: Pascal  [Select][+][-]
  1. SynEdit.Invalidate;
  2.  

That works.

Thanks.
lazarus 3.2-fpc-3.2.2-win32/win64

 

TinyPortal © 2005-2018