Author Topic: my editor project  (Read 7945 times)

zedd151

  • Member
  • *****
  • Posts: 1937
Re: my editor project
« Reply #45 on: October 09, 2022, 10:40:06 AM »
Having some issues in getting word selection working properly. That function may take a while before it gets integrated into the project. Working on finishing the file handling next. Drop file on icon (using GetCommandLine) and drop file onto editor window (using DragQueryFile)
« Last Edit: October 16, 2022, 07:06:27 PM by zedd151 »
Regards, zedd.
:tongue:

zedd151

  • Member
  • *****
  • Posts: 1937
Re: my editor project
« Reply #46 on: October 09, 2022, 05:13:47 PM »
Moving along now. Made a separate WNDPROC for the richedit control.
Now when right clicking in the richedit window, have access to the 'Edit' menu items.
Also dragging a file onto the window opens that file in the editor. Added a preliminary function to fix word selection (table based).
Also let the main window be resizable when dragging the borders.  :tongue:  I had that disabled in the window template code used.
It's beginning to look more like an editor now.  :biggrin:


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

zedd151

  • Member
  • *****
  • Posts: 1937
Re: my editor project
« Reply #47 on: October 09, 2022, 06:25:07 PM »
The word selection func still needs a little work. I've noticed some odd behavior. Nothing that would crash the editor though, but still not quite expected behaviour.  :undecided:
And I should check if contents modified before accepting the file dragged onto the editor.  :rolleyes:  Whhooops!
Needless to say a fix is in the works. First thing in the morning. Time for some ZZZzzz.
On second thought, lemme fix the dragged file thingy now. Gimme a few minutes...
Okay, the code in the attachment above has been updated to check if file in the editor has been modified (giving user chance to save it) before accepting the dragged file.
Regards, zedd.
:tongue:

jj2007

  • Member
  • *****
  • Posts: 13872
  • Assembly is fun ;-)
    • MasmBasic
Re: my editor project
« Reply #48 on: October 09, 2022, 08:01:37 PM »
I would suggest tooltips for the U R X C V etc line, otherwise it works fine :thumbsup:

zedd151

  • Member
  • *****
  • Posts: 1937
Re: my editor project
« Reply #49 on: October 10, 2022, 01:08:58 AM »
Today hopefully I will be able to finish up some of the 'half-started' functions. If I don't, I'll keep adding more functions and sooner or later will have forgotten what remains yet unfinished.  :rolleyes:
After I finish those tasks, I should try to figure out a way to do the word selection a little better. I'm not 100% satisfied with the way it currently works.  :sad:  Also "tab replacement" code needs a "code replacement".  :tongue:   Any suggestions regarding these two?
« Last Edit: October 10, 2022, 03:26:29 AM by zedd151 »
Regards, zedd.
:tongue:

zedd151

  • Member
  • *****
  • Posts: 1937
Re: my editor project
« Reply #50 on: October 10, 2022, 03:51:14 AM »
Playing around with a tip I found on the forum
Code: [Select]
invoke SendMessage, pEdit, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOWORDSELECTIONWhile this helps a little in selecting more than one word, not a cure for all ills here. More tweaking to be done...
Edit to add...
So far I am not having a lot of luck improving the current code. May have to settle for it.
Now on to replacing the tab replace code.  :cool:
« Last Edit: October 10, 2022, 05:40:10 AM by zedd151 »
Regards, zedd.
:tongue:

zedd151

  • Member
  • *****
  • Posts: 1937
Re: my editor - tab replacement code
« Reply #51 on: October 10, 2022, 06:58:29 AM »

I have been playing with alternative code to insert 4 spaces when the user presses the TAB key. Lo and behold, I had the code all the time in Masm64 example 'tEdit'. It's 64 bit code but an easy downconversion to 32 bit:biggrin:
Code: [Select]
tab_replace proc Edit:QWORD,tabs:QWORD
    LOCAL indx     :QWORD
    LOCAL diff     :QWORD
    LOCAL bal      :QWORD
    LOCAL cr       :CHARRANGE
    LOCAL hsp      :QWORD
    LOCAL psp      :QWORD
    LOCAL spbuf[16]:BYTE
    mov psp, ptr$(spbuf)
    invoke SendMessage,Edit,EM_EXGETSEL,0,ADDR cr
    mov eax, cr.cpMax
    .if cr.cpMin ~= eax                                     ; if test is selected
      invoke SendMessage,Edit,EM_REPLACESEL,TRUE,chr$(0)    ; overwrite it with keystroke
      invoke SendMessage,Edit,EM_EXGETSEL,0,ADDR cr         ; get the new selection
    .endif
    .if tabs == 0                                           ; test tab size
      mov tabs, 4                                           ; set a default tab size if zero
    .endif
    mov indx, rv(get_current_line_index,Edit)               ; get the current line index
    mov rax, indx
    .if cr.cpMin == eax                                     ; if start of line (indx = cr.cpMin)
      mov hsp, space$(psp,tabs)
      fn SendMessage,Edit,EM_REPLACESEL,TRUE,hsp            ; write "tabs" space count
      ret
    .else
      mov rax, indx
      sub cr.cpMin, eax                                     ; sub indx from cr.cpMin
      mov eax, cr.cpMin
      mov diff, rax                                         ; store it in "diff"
      xor edx, edx                                          ; clear EDX
      mov rax, diff                                         ; diff in accumulator
      div WORD PTR tabs                                     ; diff \ tabs
      mov ecx, edx                                          ; store remainder
      mul WORD PTR tabs                                     ; result * tabs
      mov rax, tabs                                         ; sub remainder from "tabs" size
      sub eax, ecx                                          ; balance in EAX
      mov bal, rax
      mov hsp, space$(psp,bal)
      fn SendMessage,Edit,EM_REPLACESEL,TRUE,hsp            ; replace selection with "bal" space count
      ret
    .endif
tab_replace endp
Now to make a 32 bit version of it.  :cool:
Regards, zedd.
:tongue:

NoCforMe

  • Member
  • *****
  • Posts: 1106
Re: my editor project
« Reply #52 on: October 10, 2022, 08:11:48 AM »
Just some side comments:
  • Tab spacing of 4? Weird; 8 is much more usual, but whatever. (4 seems more appropriate to C than to ASM.)
  • Are you inserting spaces in the file instead of tabs? I hate spaces in text files. Much harder to deal with (plus they take up that much more ... space).

One thing you might notice if you allow the user to change fonts (at least font size) is that doing so can mess up your tab spacing. But I discovered there's a really easy fix for that: immediately after selecting the new font into the RichEdit control, just reset the tab spacing (with EM_SETTABSTOPS) to whatever they were in the first place. Seems to set everything right.

jj2007

  • Member
  • *****
  • Posts: 13872
  • Assembly is fun ;-)
    • MasmBasic
Re: my editor project
« Reply #53 on: October 10, 2022, 08:18:12 AM »
I hate spaces in text files.

That is an emotionally laden debate here (but I agree with you) :bgrin:

NoCforMe

  • Member
  • *****
  • Posts: 1106
Re: my editor project
« Reply #54 on: October 10, 2022, 08:23:14 AM »
Yes, in other words a religious issue. Like indentation practice in C ...

NoCforMe

  • Member
  • *****
  • Posts: 1106
Re: my editor project
« Reply #55 on: October 10, 2022, 08:27:20 AM »
BTW, I wanted to make a general observation to Zedd. I'm sure this might have occurred to you, but the issues you're having and the problems you're solving really have little or nothing to do with assembly language: you're grappling with basic software design and implementation issues. You'd be doing the same things no matter if you're writing in C or FORTRAN or BASIC or ... whatever. Basic "algorithm" design.

Don't know about you, but I find it very useful to work out some of these problems on paper. Doesn't matter if you use flowcharting or writing pseudocode or just doodling, seeing your problem graphically can sometimes make all the difference, instead of sitting blankly in front of your screen scratching your head ...

zedd151

  • Member
  • *****
  • Posts: 1937
Re: my editor - tab replacement code
« Reply #56 on: October 10, 2022, 08:51:10 AM »
Now to make a 32 bit version of it.
Actually, no... I did convert it, but will not be using that in this editor. That function plus the accompanying functions result in around 80ish lines of code. I'd rather stick with my unauthodoxTM method. Short code and gets the job done.  :biggrin:   But I will still explore other ideas for that piece.
TM hutch--  :tongue:
Regards, zedd.
:tongue:

zedd151

  • Member
  • *****
  • Posts: 1937
Re: proper word selection
« Reply #57 on: October 10, 2022, 09:37:04 AM »
While out walking the dog, I though up a different solution to fixing the word selection problems. Suppose we catch the WM_LBUTTONDBLCLK message handler in the richedits WNDPROC. There we set a flag indicating a selection has been made. Now heres the tricky part. We then check if that flag is set in the next iteration of the message loop (we do this so the selection is made by then,  and the CHARRANGE structure contains the size and position of the selected text) for the main window and do our processing there. We get the selected text into a buffer and remove the unwanted chars/spaces from it then put the modified text back into the richedit control. All of this will be done in a procedure, called if the 'selected' flag is set, upon returning from that procedure, the 'selected' flag is set to zero. Now to implement it. :biggrin:  But its almost time for dinner, so later this evening perhaps.
Regards, zedd.
:tongue:

jj2007

  • Member
  • *****
  • Posts: 13872
  • Assembly is fun ;-)
    • MasmBasic
Re: proper word selection
« Reply #58 on: October 10, 2022, 10:00:34 AM »
word selection problems

What exactly is your "word selection problem"? I've tested your editor, and I can't see the problem.

zedd151

  • Member
  • *****
  • Posts: 1937
Re: my editor project
« Reply #59 on: October 10, 2022, 10:06:13 AM »
Code: [Select]
       
dname       db "My Editor", 0
about       db "My Editor v. ?", 0
Paste that into the latest version of the editor
Try to select the question mark by double left clicking it
There are others I noticed as well during an in-depth testing.  :cool:
Regards, zedd.
:tongue: