📄 asmedit.inc
字号:
cmp [undo_data],0
je ignore
call undo_changes
call create_caret
mov [last_operation],0
jmp text_changed
em_canundo:
mov eax,[undo_data]
or eax,eax
jz ignore
mov [return_value],TRUE
jmp ignore
em_emptyundobuffer:
call clear_undo_data
jmp ignore
em_replacesel:
test [editor_mode],AEMODE_VERTICALSEL + AEMODE_OVERWRITE
jnz ignore
cmp [undo_data],0
je replacesel_undopoint
cmp [wparam],0
je replace_undo_ok
replacesel_undopoint:
call store_status_for_undo
replace_undo_ok:
cmp [was_selection],0
je simple_replace
push [caret_line_number]
push [caret_position]
call delete_block
pop edx ecx
cmp ecx,[caret_line_number]
jne simple_replace
cmp edx,[caret_position]
jne simple_replace
mov esi,[lparam]
call insert_block
mov esi,[caret_line]
mov ecx,[caret_line_number]
mov edx,[caret_position]
xchg esi,[selection_line]
xchg ecx,[selection_line_number]
xchg edx,[selection_position]
mov [caret_line],esi
mov [caret_line_number],ecx
mov [caret_position],edx
mov [notification],AEN_TEXTCHANGE
jmp text_changed
simple_replace:
mov esi,[lparam]
call insert_block
mov [notification],AEN_TEXTCHANGE
jmp text_changed
aem_setmode:
mov eax,[wparam]
xchg [editor_mode],eax
cmp eax,[editor_mode]
je ignore
mov [notification],AEN_MODECHANGE
call create_caret
cmp [was_selection],0
jne moved_window
jmp done
aem_getmode:
mov eax,[editor_mode]
mov [return_value],eax
jmp ignore
aem_setsyntaxhighlight:
mov eax,[wparam]
mov ebx,[lparam]
mov [syntax_colors],eax
mov [syntax_proc],ebx
or eax,eax
jnz wm_size
mov [syntax_proc],SyntaxProc
jmp wm_size
aem_setrightclickmenu:
mov eax,[wparam]
mov ebx,[lparam]
mov [menu_handle],eax
mov [menu_window],ebx
jmp ignore
aem_settextcolor:
mov eax,[wparam]
mov ebx,[lparam]
mov [text_color],eax
mov [background_color],ebx
jmp wm_size
aem_setselcolor:
mov eax,[wparam]
mov ebx,[lparam]
mov [selection_text],eax
mov [selection_background],ebx
jmp wm_size
aem_setpos:
mov edi,[wparam]
virtual at edi
pos AEPOS
end virtual
cmp [selection_line],0
jne selection_current_ok
mov eax,[caret_line]
mov [selection_line],eax
mov eax,[caret_line_number]
mov [selection_line_number],eax
mov eax,[caret_position]
mov [selection_position],eax
selection_current_ok:
mov eax,[pos.selectionLine]
or eax,eax
jz selection_line_ok
call find_line
mov [selection_line],esi
mov [selection_line_number],ecx
selection_line_ok:
mov eax,[pos.selectionPosition]
sub eax,1
jc selection_position_set
mov [selection_position],eax
selection_position_set:
mov eax,[pos.caretLine]
or eax,eax
jz caret_line_ok
call find_line
mov [caret_line],esi
mov [caret_line_number],ecx
caret_line_ok:
mov eax,[pos.caretPosition]
sub eax,1
jc moved_selection
mov [caret_position],eax
jmp moved_selection
aem_getpos:
mov edi,[wparam]
mov eax,[caret_line_number]
mov [pos.selectionLine],eax
mov [pos.caretLine],eax
mov eax,[caret_position]
inc eax
mov [pos.selectionPosition],eax
mov [pos.caretPosition],eax
cmp [selection_line],0
je ignore
mov eax,[selection_line_number]
mov [pos.selectionLine],eax
mov eax,[selection_position]
inc eax
mov [pos.selectionPosition],eax
jmp ignore
aem_findfirst:
mov esi,[lparam]
mov eax,[wparam]
call find_first
jnc show_found_text
jmp ignore
aem_findnext:
call find_next
jc ignore
show_found_text:
mov eax,[caret_position]
xchg eax,[selection_position]
mov [caret_position],eax
call update_window
call let_caret_appear
call update_positions
mov eax,[caret_position]
xchg eax,[selection_position]
mov [caret_position],eax
mov [return_value],TRUE
jmp moved_selection
aem_canfindnext:
cmp [search_data],0
je ignore
mov [return_value],TRUE
jmp ignore
aem_getwordatcaret:
cmp [wparam],0
je ignore
call get_word_at_caret
mov edi,[lparam]
mov eax,[wparam]
dec eax
jz word_copied
cmp ecx,eax
jbe copy_word
mov ecx,eax
copy_word:
mov [return_value],ecx
mov esi,[caret_line]
call copy_from_line
word_copied:
xor al,al
stosb
jmp ignore
moved_caret:
test [kbstate+VK_SHIFT],80h
jnz moved_selection
mov [selection_line],0
moved_selection:
mov [notification],AEN_POSCHANGE
jmp update_all
moved_window:
call update_positions
jmp refresh
text_altered:
mov [selection_line],0
text_changed:
mov [notification],AEN_TEXTCHANGE
mov eax,[peak_line_length]
xor edx,edx
mov ebx,SEGMENT_DATA_LENGTH
div ebx
inc eax
mul ebx
shl eax,1
cmp eax,[line_buffer_size]
je update_all
mov [line_buffer_size],eax
invoke VirtualAlloc,0,[line_buffer_size],MEM_COMMIT,PAGE_READWRITE
or eax,eax
jz memory_shortage
xchg [line_buffer],eax
invoke VirtualFree,eax,0,MEM_RELEASE
update_all:
call update_window
call let_caret_appear
call update_positions
refresh:
cmp [screen_base],0
je wm_size
mov eax,[screen_size]
shl eax,1
xor [screen_offset],eax
call update_screen
mov esi,[screen_base]
mov eax,[screen_size]
lea edi,[esi+eax*2]
mov [rect.top],0
mov edx,[font_height]
mov [rect.bottom],edx
mov ecx,[screen_height]
refresh_screen:
push ecx
mov ebx,[screen_size]
mov edx,[font_width]
xor eax,eax
mov [rect.left],eax
mov [rect.right],eax
mov ecx,[screen_width]
refresh_line:
mov al,[esi]
mov ah,[esi+ebx]
cmp al,[edi]
jne refresh_changed
cmp ah,[edi+ebx]
jne refresh_changed
inc esi
inc edi
add [rect.left],edx
add [rect.right],edx
loop refresh_line
jmp refresh_next_line
refresh_changed:
mov al,[esi]
mov ah,[esi+ebx]
inc esi
add [rect.right],edx
cmp al,[edi]
jne changed_more
cmp ah,[edi+ebx]
jne changed_more
inc edi
jmp invalidate
changed_more:
inc edi
loop refresh_changed
invalidate:
push ecx edx
lea eax,[rect]
invoke InvalidateRect,[hwnd],eax,FALSE
pop edx ecx
mov eax,[rect.right]
mov [rect.left],eax
jecxz refresh_next_line
loop refresh_line
refresh_next_line:
mov eax,[font_height]
add [rect.top],eax
add [rect.bottom],eax
pop ecx
dec ecx
jnz refresh_screen
jmp done
ignore:
mov dl,[last_operation]
mov [current_operation],dl
cmp [was_selection],0
jne done
mov [selection_line],0
done:
cmp [focus],0
je caret_ok
call update_caret_position
invoke ShowCaret,[hwnd]
caret_ok:
lea esi,[editor_data]
mov edi,[editor_memory]
add edi,16
mov ecx,editor_data_size
rep movsb
cmp [notification],0
je notification_ok
invoke GetWindowLong,[hwnd],GWL_HWNDPARENT
mov edi,eax
invoke GetWindowLong,[hwnd],GWL_ID
movzx ebx,[notification]
shl ebx,16
or eax,ebx
invoke SendMessage,edi,WM_COMMAND,eax,[hwnd]
notification_ok:
cmp [redraw_now],0
je redraw_ok
invoke UpdateWindow,[hwnd]
redraw_ok:
mov eax,[return_value]
finish_wndproc:
pop edi esi ebx
ret
not_enough_memory:
lea esp,[editor_memory-10h]
mov [notification],AEN_OUTOFMEMORY
or [return_value],-1
cmp [clipboard_opened],0
je ignore
invoke CloseClipboard
mov [clipboard_opened],0
jmp ignore
get_memory:
invoke VirtualAlloc,0,ecx,MEM_COMMIT,PAGE_READWRITE
mov ebx,eax
retn
release_memory:
invoke VirtualFree,ebx,0,MEM_RELEASE
retn
update_positions:
lea eax,[rect]
invoke GetClientRect,[hwnd],eax
mov eax,[rect.right]
sub eax,[rect.left]
cdq
div [font_width]
mov [window_width],eax
add edx,-1
adc eax,0
mov [screen_width],eax
mov eax,[rect.bottom]
sub eax,[rect.top]
cdq
div [font_height]
mov [window_height],eax
add edx,-1
adc eax,0
mov [screen_height],eax
call update_window
setup_vscroll:
mov ecx,[lines_count]
mov [sc.cbSize],sizeof.SCROLLINFO
mov [sc.fMask],SIF_DISABLENOSCROLL+SIF_RANGE+SIF_PAGE+SIF_POS
mov [sc.nMin],1
mov [sc.nMax],ecx
mov eax,[window_height]
mov [sc.nPage],eax
mov edx,[window_line_number]
mov [sc.nPos],edx
test [editor_style],WS_VSCROLL
jz setup_hscroll
lea eax,[sc]
invoke SetScrollInfo,[hwnd],SB_VERT,eax,TRUE
setup_hscroll:
mov ecx,[maximum_position]
mov [sc.nMin],0
mov [sc.nMax],ecx
mov eax,[window_width]
mov [sc.nPage],eax
mov edx,[window_position]
mov [sc.nPos],edx
test [editor_style],WS_HSCROLL
jz setup_caret
lea eax,[sc]
invoke SetScrollInfo,[hwnd],SB_HORZ,eax,TRUE
setup_caret:
mov eax,[font_width]
mov edx,[caret_position]
sub edx,[window_position]
imul eax,edx
mov [caret_x],eax
mov eax,[font_height]
mov edx,[caret_line_number]
sub edx,[window_line_number]
imul eax,edx
mov [caret_y],eax
retn
create_caret:
xor eax,eax
test [editor_mode],AEMODE_OVERWRITE
jnz block_caret
test [editor_style],AES_CONSOLECARET
jnz console_caret
invoke CreateCaret,[hwnd],NULL,0,[font_height]
jmp update_caret_position
block_caret:
invoke CreateCaret,[hwnd],NULL,[font_width],[font_height]
jmp update_caret_position
console_caret:
invoke CreateCaret,[hwnd],NULL,[font_width],2
update_caret_position:
mov eax,[caret_y]
test [editor_mode],AEMODE_OVERWRITE
jnz set_position
test [editor_style],AES_CONSOLECARET
jz set_position
add eax,[font_height]
sub eax,2
set_position:
invoke SetCaretPos,[caret_x],eax
retn
update_screen:
mov edi,[screen_base]
or edi,edi
jz screen_prepared
add edi,[screen_offset]
mov ebx,[screen_size]
add ebx,edi
push ebx
mov ecx,[screen_height]
mov esi,[window_line]
prepare_screen:
push ecx
test byte [esi],1
jnz prepare_long_line
push esi
add esi,SEGMENT_HEADER_LENGTH
mov ecx,SEGMENT_DATA_LENGTH
call prepare_line
pop esi
mov esi,[esi]
jmp prepare_next_line
prepare_long_line:
push edi
mov edi,[line_buffer]
xor eax,eax
combine_long_line_segments:
add esi,SEGMENT_HEADER_LENGTH
mov ecx,SEGMENT_DATA_LENGTH
rep movsb
add eax,SEGMENT_DATA_LENGTH
mov esi,[esi-SEGMENT_LENGTH]
btr esi,0
jc combine_long_line_segments
mov ecx,eax
mov eax,esi
mov esi,edi
sub esi,ecx
pop edi
push eax
call prepare_line
pop esi
prepare_next_line:
pop ecx
dec ecx
jz prepare_selection
or esi,esi
jnz prepare_screen
prepare_empty_lines:
imul ecx,[screen_width]
xor al,al
mov edx,ecx
rep stosb
xchg edi,ebx
mov ecx,edx
rep stosb
prepare_selection:
pop ebx
test [editor_style],ES_NOHIDESEL
jnz hideselection_ok
cmp [focus],0
je screen_prepared
hideselection_ok:
cmp [selection_line],0
je screen_prepared
mov eax,[window_line_number]
mov esi,[selection_line_number]
mov edi,[caret_line_number]
sub esi,eax
sub edi,eax
mov ecx,[window_position]
mov eax,[selection_position]
mov edx,[caret_position]
sub eax,ecx
sub edx,ecx
cmp esi,edi
jle selection_boundaries_ok
xchg esi,edi
xchg eax,edx
selection_boundaries_ok:
mov ecx,[screen_height]
cmp edi,0
jl screen_prepared
cmp esi,ecx
jge screen_prepared
cmp esi,edi
je prepare_vsel
test [editor_mode],AEMODE_VERTICALSEL
jz prepare_hsel
prepare_vsel:
cmp eax,edx
jle vselection_boundaries_ok
xchg eax,edx
vselection_boundaries_ok:
cmp esi,0
jge vselection_start_ok
xor esi,esi
vselection_start_ok:
inc edi
cmp edi,ecx
jle vselection_end_ok
mov edi,ecx
vselection_end_ok:
mov ecx,[screen_width]
cmp edx,0
jl screen_prepared
cmp eax,ecx
jge screen_prepared
cmp eax,0
jge vselection_line_start_ok
xor eax,eax
vselection_line_start_ok:
cmp edx,ecx
jle vselection_line_end_ok
mov edx,ecx
vselection_line_end_ok:
mov ecx,edi
sub ecx,esi
imul esi,[screen_width]
add ebx,esi
prepare_vselection_line:
push eax ecx
mov edi,ebx
mov ecx,edx
sub ecx,eax
lea edi,[ebx+eax]
mov al,80h
rep stosb
add ebx,[screen_width]
pop ecx eax
loop prepare_vselection_line
jmp screen_prepared
prepare_hsel:
cmp esi,0
jge hselection_start_ok
xor esi,esi
xor eax,eax
hselection_start_ok:
cmp edi,ecx
jl hselection_end_ok
mov edi,ecx
xor edx,edx
hselection_end_ok:
inc esi
mov ecx,edi
sub ecx,esi
imul ecx,[screen_width]
imul esi,[screen_width]
lea edi,[ebx+esi]
neg eax
add eax,[screen_width]
cmp eax,0
jle hselection_start_line_ok
sub edi,eax
add ecx,eax
sub eax,[screen_width]
jle hselection_start_line_ok
add edi,eax
sub ecx,eax
hselection_start_line_ok:
cmp edx,0
jle hselection_end_line_ok
add ecx,edx
sub edx,[screen_width]
jle hselection_end_line_ok
sub ecx,edx
hselection_end_line_ok:
mov al,80h
rep stosb
screen_prepared:
retn
prepare_line:
push edi ecx
mov ecx,[esp]
mov edi,[line_buffer]
add edi,ecx
shr ecx,2
xor eax,eax
rep stosd
mov ecx,[esp]
sub edi,ecx
invoke syntax_proc,esi,ecx,edi
mov edx,edi
pop eax edi
push esi edx
mov edx,[window_position]
lea esi,[esi+edx]
sub eax,edx
jnc line_position_ok
xor eax,eax
jmp line_length_ok
line_position_ok:
cmp eax,[screen_width]
jbe line_length_ok
mov eax,[screen_width]
line_length_ok:
mov ecx,eax
rep movsb
pop esi
add esi,edx
mov ecx,eax
xchg edi,ebx
rep movsb
xchg edi,ebx
pop esi
cmp eax,[screen_width]
jb after_end_of_line
retn
after_end_of_line:
mov ecx,[screen_width]
sub ecx,eax
xor al,al
mov edx,ecx
rep stosb
xchg edi,ebx
mov ecx,edx
rep stosb
xchg edi,ebx
retn
include '..\memory.inc'
include '..\navigate.inc'
include '..\edit.inc'
include '..\blocks.inc'
include '..\search.inc'
include '..\undo.inc'
endp
proc SyntaxProc lpLine,uChars,lpColors
ret
endp
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -