Author Topic: my editor project  (Read 10702 times)

zedd151

  • Member
  • *****
  • Posts: 1968
Re: my editor project - new search & replace
« Reply #120 on: October 13, 2022, 05:11:42 PM »
A couple minor changes. Since both search and replace use the same dialog box, made "S&R" a menu item on the menu bar and removed the "search" menu. and another minor change (you won't even notice :tongue: )


To find text enter text to find and use UP or DN button to find it.
To replace,  select portion of text or select all, enter text to replace(Find Text), enter text to Replace With, click Replace.
No need to use UP/DN button to replace.
For Go to Line Number, enter line number (decimal) press Go To.   :biggrin:


Attachment 'basic editor15.zip' removed but is included in the archive In this post
« Last Edit: November 17, 2022, 12:46:07 PM by zedd151 »
Regards, zedd.
:tongue:

zedd151

  • Member
  • *****
  • Posts: 1968
Re: my editor project
« Reply #121 on: October 13, 2022, 05:53:46 PM »
Next up... since we have a function to go to a specified line number, we now need the means to display the line number (and column). So I will give the editor a status bar and add code for displaying the line number and column next. But that will be tomorrow (actually later today, it's almost 2 A.M. here)...


Before I go for the night, just want to mention I also should comment the search and replace code.  :smiley:
And add a help file (instructions for use). A simple text file for now.   Now this little editor is starting to take shape  :biggrin:
Regards, zedd.
:tongue:

jj2007

  • Member
  • *****
  • Posts: 13958
  • Assembly is fun ;-)
    • MasmBasic
Re: my editor project
« Reply #122 on: October 13, 2022, 08:36:49 PM »
Wellll, you ought to give the user the choice of replacing the next match (and the next and the next and the next ...) or replacing everything. Lots of times you don't want to replace all occurrences.

Replacing text this way is a bit trickier (replacing all is easy peasy, just loop until you find no more matches).

With "replace all", make sure you start from the bottom, because otherwise you will have to adjust for difference of length between find and replace strings.

zedd151

  • Member
  • *****
  • Posts: 1968
my editor - Line Number and Column Number
« Reply #123 on: October 14, 2022, 03:10:56 AM »
I have inserted statusbar code and code to get the line number and column number of the current caret position, and to display it on the status bar.

Attachment 'basic editor16.zip' removed but is included in the archive In this post
« Last Edit: November 17, 2022, 12:46:40 PM by zedd151 »
Regards, zedd.
:tongue:

C3

  • Regular Member
  • *
  • Posts: 39
Re: my editor project
« Reply #124 on: October 14, 2022, 04:28:15 AM »
Hi,

Zedd.. since you started so recently, you should go on 64bit. Now you have double the work writing it again to 64bits.

C3

zedd151

  • Member
  • *****
  • Posts: 1968
Re: my editor project
« Reply #125 on: October 14, 2022, 04:33:33 AM »
Hi C3, actually I spent a full day experimenting with converting the then existing code to 64 bits. I don't think that it would be worthwhile actually, since 32 bit programs can still run in a 64 bit environment. Also, it would take me much longer to write that code since I am hardly 64 bit fluent. But thanks for the suggestion.
Regards, zedd.
:tongue:

NoCforMe

  • Member
  • *****
  • Posts: 1124
Re: my editor project
« Reply #126 on: October 14, 2022, 06:36:38 AM »
With "replace all", make sure you start from the bottom, because otherwise you will have to adjust for difference of length between find and replace strings.

JJ, are you sure about that? I don't do that (start from the bottom): after I replace text, I just start the next search from the end of the replacement, which works fine. The code isn't complicated.

zedd151

  • Member
  • *****
  • Posts: 1968
Re: my editor project
« Reply #127 on: October 14, 2022, 06:50:42 AM »
JJ, are you sure about that?
  :cool:  as for me...
The algo in my current 'replace text' type function puts the selected text into a buffer and performs the replacement while copying to a second buffer. Then the contents of the second buffer are put into the richedit control, overwriting the previous contents. simple and fast enough.  :biggrin: 
Regards, zedd.
:tongue:

NoCforMe

  • Member
  • *****
  • Posts: 1124
Re: my editor project
« Reply #128 on: October 14, 2022, 07:13:13 AM »
That's fine; whatever works for you, so long as it works ...

jj2007

  • Member
  • *****
  • Posts: 13958
  • Assembly is fun ;-)
    • MasmBasic
Re: my editor project
« Reply #129 on: October 14, 2022, 07:45:21 AM »
With "replace all", make sure you start from the bottom, because otherwise you will have to adjust for difference of length between find and replace strings.

JJ, are you sure about that? I don't do that (start from the bottom): after I replace text, I just start the next search from the end of the replacement, which works fine. The code isn't complicated.

You are right, that should work, too. It depends on how the code is organised. RichMasm maintains a dword table of the positions of the matches (those in the listbox), so I don't have to search again if I start from the bottom.

zedd151

  • Member
  • *****
  • Posts: 1968
Re: my editor project
« Reply #130 on: October 14, 2022, 11:04:09 AM »
RichMasm maintains a dword table of the positions of the matches (those in the listbox), so I don't have to search again if I start from the bottom.
That sounds like a novel approach, sort of like tokens? Sounds like it should be super fast...
Regards, zedd.
:tongue:

NoCforMe

  • Member
  • *****
  • Posts: 1124
Re: my editor project
« Reply #131 on: October 14, 2022, 11:15:13 AM »
Dunno how you get "tokens" out of that. More of a cache, really.

And of course it'll be fast. Why wouldn't it be?

zedd151

  • Member
  • *****
  • Posts: 1968
Re: my editor project
« Reply #132 on: October 14, 2022, 11:19:49 AM »
I said "sort of', as he has an array of offsets just like would be used for tokenized lines of text.  :undecided:  Jeez.
Regards, zedd.
:tongue:

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 10583
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: my editor project
« Reply #133 on: October 14, 2022, 12:25:31 PM »
If you don't mind writing the algo (or using one of the library ones), for global replace, grab the entire edit content into memory, global replace on the memory then write the results back to the editor. If you can stay at the same or similar line number after, its easier to use.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

jj2007

  • Member
  • *****
  • Posts: 13958
  • Assembly is fun ;-)
    • MasmBasic
Re: my editor project
« Reply #134 on: October 14, 2022, 12:47:14 PM »
RichMasm maintains a dword table of the positions of the matches (those in the listbox), so I don't have to search again if I start from the bottom.
That sounds like a novel approach, sort of like tokens? Sounds like it should be super fast...

Speedwise, I don't think it makes a difference. Replacing "varGood" with "varBad" requires shifting everything below the current position up by one byte, whether you use a table or a new search doesn't matter. This is a relatively slow operation, especially for a richedit control.

One advantage of the table approach is that it allows to limit replacing to a certain range, as shown below; only the 5 txrg inside the ContG procedure will be replaced with txrgCG: