Subversion Repositories Kolibri OS

Rev

Rev 4566 | Rev 5838 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. diff16 'tp-key.asm',0,$
  2.  
  3. key:
  4.         mov     ecx,1
  5.         mcall   66,3            ; Get status of the control keys
  6.         mov     [shi],eax
  7.         xor     ebx,ebx
  8.         test    al,0x03         ; Left or right shift
  9.         jz      @f
  10.         or      ebx,KM_SHIFT
  11.     @@: test    al,0x0C         ; Left or right control
  12.         jz      @f
  13.         or      ebx,KM_CTRL
  14.     @@: test    al,0x10         ; Left alt
  15.         jz      @f
  16.         or      ebx,KM_ALT
  17.     @@: mov     edx,ebx
  18.         test    al,0x03
  19.         jz      @f
  20.         inc     cl
  21.     @@:
  22.         mcall   2
  23.         cmp     al,0
  24.         jne     still.skip_write
  25.         shr     eax,8
  26. ;--------------------------------------
  27. ; this code for Win-keys, works with
  28. ; kernel SVN r.3356 or later
  29.         test    [shi],0x200     ; LWin
  30.         jnz     still.skip_write
  31.         test    [shi],0x400     ; RWin
  32.         jnz     still.skip_write
  33. ;--------------------------------------
  34.         cmp     al,224
  35.         jne     @f
  36.         mov     [ext],0x01
  37.         jmp     still.skip_write
  38.     @@: cmp     al,225
  39.         jne     @f
  40.         mov     [ext],0x02
  41.         jmp     still.skip_write
  42.     @@:
  43.         mov     ah,[ext]
  44.         mov     [ext],0
  45.  
  46.         mov     esi,numpad_table_off
  47.         test    [shi], 0x00000080 ; NumLock is on?
  48.         jz      .num
  49.         mov     esi,numpad_table_on
  50.   .num: cmp     eax,[esi]
  51.         jne     @f
  52.         mov     eax,[esi+4]
  53.         mov     ebx,eax
  54.         or      eax,edx
  55.         shr     ebx,8
  56.         or      ebx,0x0000FFFF
  57.         and     eax,ebx
  58.         mov     ecx,eax
  59.         shr     ecx,16
  60.         and     cl,1
  61.         inc     cl
  62.         jmp     .lp0
  63.     @@: add     esi,8
  64.         cmp     dword[esi],0
  65.         jne     .num
  66.  
  67.         or      eax,edx
  68.  
  69.   .lp0: test    al,0x80
  70.         jnz     still.skip_write
  71. ;--------------------------------------
  72. ; it is CAPS LOCK correct processing for chars
  73.         test    [shi], 0x00000040 ; CAPS LOCK is on?
  74.         jz      .no_caps_lock
  75.         cmp     ecx,1
  76.         jnz     @f
  77.         inc     ecx
  78.         jmp     .no_caps_lock
  79. @@:
  80.         cmp     ecx,2
  81.         jnz     .no_caps_lock
  82.         dec     ecx
  83. .no_caps_lock:
  84. ;--------------------------------------
  85. ; alt gr pressed?
  86.         test    [shi], 0x00000020
  87.         jz      .no_alt_gr
  88.         mov     ecx, 3
  89.   .no_alt_gr:
  90. ;--------------------------------------
  91.         push    eax
  92.         mcall   26,2,,key1
  93.         pop     eax
  94.  
  95.         mov     [chr],eax
  96.  
  97.         cmp     [bot_mode],0
  98.         je      @f
  99.         mov     ebx,eax
  100.         mov     al,2
  101.         call    [bot_dlg_handler]
  102.         jmp     still.skip_write
  103.     @@:
  104.  
  105.         mov     esi,accel_table_main
  106.   .acc: cmp     eax,[esi]
  107.         jne     @f
  108.         test    [secure_sel],1
  109.         jz      .lp1
  110.         m2m     [cur_editor.SelStart.X],[cur_editor.Caret.X]
  111.         m2m     [cur_editor.SelStart.Y],[cur_editor.Caret.Y]
  112.   .lp1: mov     [s_status],0
  113.         call    dword[esi+4]
  114.         call    editor_check_for_changes
  115.         jmp     still
  116.     @@: add     esi,8
  117.         cmp     dword[esi],0
  118.         jne     .acc
  119.  
  120.         test    [chr],KM_CTRLALT
  121.         jnz     still.skip_write
  122.  
  123.         mov     [s_status],0
  124.  
  125.         movzx   eax,byte[chr]
  126.         movzx   eax,[eax+key0]
  127.         or      al,al
  128.         jz      still.skip_write
  129.         movzx   eax,[eax+key1]
  130.         push    eax
  131.  
  132.         test    [secure_sel],1
  133.         jz      .lp2
  134.         m2m     [cur_editor.SelStart.X],[cur_editor.Caret.X]
  135.         m2m     [cur_editor.SelStart.Y],[cur_editor.Caret.Y]
  136.         jmp     .put
  137.   .lp2: call    delete_selection
  138.  
  139.         test    [auto_braces],1
  140.         jz      .put
  141.         cmp     al,'['
  142.         jne     @f
  143.         mov     al,']'
  144.         call    .lp3
  145.         dec     [cur_editor.Caret.X]
  146.         jmp     .put
  147.     @@: cmp     al,'('
  148.         jne     @f
  149.         mov     al,')'
  150.         call    .lp3
  151.         dec     [cur_editor.Caret.X]
  152.         jmp     .put
  153.     @@: cmp     al,'{'
  154.         jne     .put
  155.         mov     al,'}'
  156.         call    .lp3
  157.         dec     [cur_editor.Caret.X]
  158.  
  159.   .put: pop     eax
  160.         push    still editor_check_for_changes
  161.         inc     [cur_editor.SelStart.X]
  162.   .lp3: push    [cur_editor.Caret.X] eax
  163.         inc     dword[esp+4]
  164.         mov     eax,1
  165.         jmp     key.tab.direct
  166.  
  167. ;-----------------------------------------------------------------------------
  168. proc key.ctrl_a ;///// SELECT ALL DOCUMENT ///////////////////////////////////
  169. ;-----------------------------------------------------------------------------
  170.         xor     eax,eax
  171.         mov     [cur_editor.SelStart.X],eax
  172.         mov     [cur_editor.SelStart.Y],eax
  173.         mov     ecx,[cur_editor.Lines.Count]
  174.         dec     ecx
  175.         mov     [cur_editor.Caret.Y],ecx
  176.         call    get_line_offset
  177.         call    get_real_length
  178.         mov     [cur_editor.Caret.X],eax
  179.         call    draw_editor
  180.         ret
  181. endp
  182.  
  183. ;-----------------------------------------------------------------------------
  184. proc key.ctrl_o ;///// ENTER OPEN FILENAME ///////////////////////////////////
  185. ;-----------------------------------------------------------------------------
  186.         mov     [bot_mode2],0
  187.  
  188.   .direct:
  189.         cmp     [bot_mode2], 2
  190.         je      .ask
  191.         mov     [s_status],s_enter_filename
  192.         jmp     .ask1
  193.  
  194.    .ask:
  195.         mov     [s_status],s_ask_save
  196.   .ask1:
  197.         mov     [bot_mode],1
  198.         mov     [bot_dlg_height],16*2+4*2-1
  199.         mov     [bot_dlg_handler],osdlg_handler
  200.         mov     [focused_tb],tb_opensave
  201.  
  202.     @@: mov     al,[tb_opensave.length]
  203.         mov     [tb_opensave.pos.x],al
  204.         mov     [tb_opensave.sel.x],0
  205.         mov     [tb_casesen],0;1
  206.         call    drawwindow
  207.         ret
  208. endp
  209.  
  210. ;-----------------------------------------------------------------------------
  211. proc key.ctrl_s ;///// ENTER SAVE FILENAME ///////////////////////////////////
  212. ;-----------------------------------------------------------------------------
  213.         cmp     [cur_editor.FilePath], 0
  214.         je      key.shift_ctrl_s
  215.         cmp     [cur_editor.Modified],0
  216.         je      .exit
  217.         call    save_file
  218.         call    drawwindow
  219.   .exit:
  220.         ret
  221.  
  222.     key.shift_ctrl_s:
  223.         mov     [bot_mode2],1
  224.         jmp     key.ctrl_o.direct
  225. endp
  226.  
  227. ;-----------------------------------------------------------------------------
  228. proc key.ctrl_n ;///// CREATE NEW FILE (TAB) /////////////////////////////////
  229. ;-----------------------------------------------------------------------------
  230.         call    create_tab
  231.         ret
  232. endp
  233.  
  234. ;-----------------------------------------------------------------------------
  235. proc key.ctrl_f ;///// ENTER KEYWORD TO FIND /////////////////////////////////
  236. ;-----------------------------------------------------------------------------
  237.         mov     [bot_mode2],0
  238.         mov     [bot_dlg_height],16*2+4*2-1
  239.  
  240.         mov     [s_status],s_enter_text_to_find
  241.  
  242.   .direct:
  243.         mov     [bot_mode],1
  244.         mov     [bot_dlg_handler],finddlg_handler
  245.         mov     [focused_tb],tb_find
  246.  
  247.         mov     ecx,[s_search.size]
  248.         mov     [tb_find.length],cl
  249.         jecxz   @f
  250.         mov     esi,s_search
  251.         mov     edi,tb_find.text
  252.         cld
  253.         rep     movsb
  254.  
  255.     @@: mov     al,[tb_find.length]
  256.         mov     [tb_find.pos.x],al
  257.         mov     [tb_find.sel.x],0
  258.         mov     [tb_casesen],0
  259.         call    drawwindow
  260.         ret
  261. endp
  262.  
  263. proc key.ctrl_h
  264.         mov     [bot_mode2],1
  265.         mov     [bot_dlg_height],16*3+4*2+1
  266.  
  267.         mov     [s_status],s_enter_text_to_replace
  268.  
  269.         jmp     key.ctrl_f.direct
  270. endp
  271.  
  272. proc key.ctrl_g
  273.         ret
  274. @^
  275.         mov     [bot_mode2],0
  276.         mov     [bot_dlg_height],16*2+4*2-1
  277.  
  278.         mov     [bot_mode],1
  279.         mov     [bot_dlg_handler],gotodlg_handler
  280.         mov     [focused_tb],tb_gotorow
  281.  
  282.         mov     al,[tb_gotorow.length]
  283.         mov     [tb_gotorow.pos.x],al
  284.         mov     [tb_gotorow.sel.x],0
  285.         mov     [tb_casesen],0
  286.         call    drawwindow
  287.         ret
  288. ^@
  289. endp
  290.  
  291. ;-----------------------------------------------------------------------------
  292. proc key.ctrl_left ;///// GO TO PREVIOUS WORD ////////////////////////////////
  293. ;-----------------------------------------------------------------------------
  294.         call    clear_selection
  295.  
  296. ;-----------------------------------------------------------------------------
  297.      key.shift_ctrl_left: ;///// GO TO PREVIOUS WORD, WITH SELECTION /////////
  298. ;-----------------------------------------------------------------------------
  299.         mov     ebx,[cur_editor.Caret.Y]
  300.         mov     edx,[cur_editor.Caret.X]
  301.         cld
  302.         mov     ecx,ebx
  303.         call    get_line_offset
  304.   .lp1: cmp     edx,[esi+EDITOR_LINE_DATA.Size]
  305.         jle     @f
  306.         mov     edx,[esi+EDITOR_LINE_DATA.Size]
  307.     @@: dec     edx
  308.         jl      .nx1
  309.         add     esi,sizeof.EDITOR_LINE_DATA
  310.         add     esi,edx
  311.         mov     ecx,edx
  312.     @@: push    ecx
  313.         mov     edi,symbols_ex
  314.         mov     ecx,symbols_ex.size+symbols.size
  315.         mov     al,[esi]
  316.         dec     esi
  317.         repne   scasb
  318.         pop     ecx
  319.         jne     @f
  320.         dec     edx
  321.         dec     ecx
  322.         jnz     @b
  323.   .nx1: dec     ebx
  324.         js      .exit.2
  325.         mov     ecx,ebx
  326.         call    get_line_offset
  327.         mov     edx,[esi+EDITOR_LINE_DATA.Size]
  328.         dec     edx
  329.         jmp     .lp1
  330.     @@:
  331.         mov     ecx,ebx
  332.         call    get_line_offset
  333.   .lp2: cmp     edx,[esi+EDITOR_LINE_DATA.Size]
  334.         jle     @f
  335.         mov     edx,[esi+EDITOR_LINE_DATA.Size]
  336.     @@: or      edx,edx
  337.         jl      .nx2
  338.         add     esi,sizeof.EDITOR_LINE_DATA
  339.         add     esi,edx
  340.     @@: mov     edi,symbols_ex
  341.         mov     ecx,symbols_ex.size+symbols.size
  342.         mov     al,[esi]
  343.         dec     esi
  344.         repne   scasb
  345.         je      @f
  346.         dec     edx
  347.         jns     @b
  348.         jmp     @f
  349.   .nx2: dec     ebx
  350.         js      .exit.2
  351.         mov     ecx,ebx
  352.         call    get_line_offset
  353.         mov     edx,[esi+EDITOR_LINE_DATA.Size]
  354.         dec     edx
  355.         jmp     .lp2
  356.     @@:
  357.         inc     edx
  358.         mov     [cur_editor.Caret.Y],ebx
  359.         mov     [cur_editor.Caret.X],edx
  360.         test    [chr],KM_SHIFT
  361.         jnz     @f
  362.         mov     [cur_editor.SelStart.Y],ebx
  363.         mov     [cur_editor.SelStart.X],edx
  364.     @@: sub     ebx,[cur_editor.TopLeft.Y]
  365.         jge     @f
  366.         add     [cur_editor.TopLeft.Y],ebx
  367.     @@: mov     eax,edx
  368.         sub     eax,[cur_editor.TopLeft.X]
  369.         cmp     eax,[columns.scr]
  370.         jl      @f
  371.         sub     eax,[columns.scr]
  372.         inc     eax
  373.         add     [cur_editor.TopLeft.X],eax
  374.         jmp     .exit
  375.     @@: cmp     edx,[cur_editor.TopLeft.X]
  376.         jge     .exit
  377.         mov     [cur_editor.TopLeft.X],edx
  378.   .exit:
  379.         call    editor_check_for_changes
  380.   .exit.2:
  381.         ret
  382. endp
  383.  
  384. ;-----------------------------------------------------------------------------
  385. proc key.ctrl_right ;///// GO TO NEXT WORD ///////////////////////////////////
  386. ;-----------------------------------------------------------------------------
  387.         call    clear_selection
  388.  
  389. ;-----------------------------------------------------------------------------
  390.      key.shift_ctrl_right: ;///// GO TO NEXT WORD, WITH SELECTION ////////////
  391. ;-----------------------------------------------------------------------------
  392.         mov     ebx,[cur_editor.Caret.Y]
  393.         mov     edx,[cur_editor.Caret.X]
  394.         cld
  395.   .lp1: mov     ecx,ebx
  396.         call    get_line_offset
  397.         mov     ecx,[esi+EDITOR_LINE_DATA.Size]
  398.         cmp     edx,ecx
  399.         jge     .nx1
  400.         add     esi,sizeof.EDITOR_LINE_DATA
  401.         add     esi,edx
  402.         sub     ecx,edx
  403.     @@: push    ecx
  404.         mov     edi,symbols_ex
  405.         mov     ecx,symbols_ex.size+symbols.size
  406.         lodsb
  407.         repne   scasb
  408.         pop     ecx
  409.         je      @f
  410.         inc     edx
  411.         dec     ecx
  412.         jnz     @b
  413.   .nx1: inc     ebx
  414.         cmp     ebx,[cur_editor.Lines.Count]
  415.         jge     .exit.2
  416.         xor     edx,edx
  417.         jmp     .lp1
  418.     @@:
  419.  
  420.   .lp2: mov     ecx,ebx
  421.         call    get_line_offset
  422.         mov     ecx,[esi+EDITOR_LINE_DATA.Size]
  423.         cmp     edx,ecx
  424.         jge     .nx2
  425.         add     esi,sizeof.EDITOR_LINE_DATA
  426.         add     esi,edx
  427.         sub     ecx,edx
  428.     @@: push    ecx
  429.         mov     edi,symbols_ex
  430.         mov     ecx,symbols_ex.size+symbols.size
  431.         lodsb
  432.         repne   scasb
  433.         pop     ecx
  434.         jne     @f
  435.         inc     edx
  436.         dec     ecx
  437.         jnz     @b
  438.   .nx2: inc     ebx
  439.         cmp     ebx,[cur_editor.Lines.Count]
  440.         jge     .exit.2
  441.         xor     edx,edx
  442.         jmp     .lp2
  443.     @@:
  444.         mov     [cur_editor.Caret.Y],ebx
  445.         mov     [cur_editor.Caret.X],edx
  446.         test    [chr],KM_SHIFT
  447.         jnz     @f
  448.         mov     [cur_editor.SelStart.Y],ebx
  449.         mov     [cur_editor.SelStart.X],edx
  450.     @@: sub     ebx,[cur_editor.TopLeft.Y]
  451.         cmp     ebx,[lines.scr]
  452.         jl      @f
  453.         sub     ebx,[lines.scr]
  454.         inc     ebx
  455.         add     [cur_editor.TopLeft.Y],ebx
  456.     @@: mov     eax,edx
  457.         sub     eax,[cur_editor.TopLeft.X]
  458.         cmp     eax,[columns.scr]
  459.         jl      @f
  460.         sub     eax,[columns.scr]
  461.         inc     eax
  462.         add     [cur_editor.TopLeft.X],eax
  463.         jmp     .exit
  464.     @@: cmp     edx,[cur_editor.TopLeft.X]
  465.         jge     .exit
  466.         mov     [cur_editor.TopLeft.X],edx
  467.   .exit:
  468.         call    editor_check_for_changes
  469.   .exit.2:
  470.         ret
  471. endp
  472.  
  473. ;-----------------------------------------------------------------------------
  474. proc key.ctrl_x
  475.         cmp     [sel.selected],0
  476.         je      @f
  477.         call    key.ctrl_c
  478.         call    key.del
  479.         mov     [cur_editor.Modified],1
  480.     @@: ret
  481. endp
  482.  
  483. ;-----------------------------------------------------------------------------
  484. proc key.ctrl_c
  485.         mov     [copy_size],0
  486.         cmp     [sel.selected],0
  487.         je      .exit
  488.  
  489.         call    get_selection_size
  490.         push    eax
  491.         stdcall mem.ReAlloc,[copy_buf],eax
  492.         mov     [copy_buf],eax
  493.         pop     eax
  494.         stdcall mem.ReAlloc,[clipboard_buf],eax
  495.         mov     [clipboard_buf],eax
  496.  
  497.         cld
  498.         mov     eax,[sel.begin.y]
  499.         cmp     eax,[sel.end.y]
  500.         je      .single_line
  501.         mov     ecx,[sel.begin.y]
  502.         call    get_line_offset
  503.         inc     ecx
  504.         push    ecx
  505.         mov     edi,[copy_buf]
  506.         call    get_real_length
  507.         sub     eax,[sel.begin.x]
  508.         jge     @f
  509.         xor     eax,eax
  510.     @@: add     esi,[sel.begin.x]
  511.         add     esi,sizeof.EDITOR_LINE_DATA
  512.         mov     [edi+EDITOR_LINE_DATA.Size],eax
  513.         add     edi,sizeof.EDITOR_LINE_DATA
  514.         mov     ecx,eax
  515.         jecxz   @f
  516.         rep     movsb
  517.     @@: mov     ecx,[sel.end.y]
  518.         call    get_line_offset
  519.         pop     ecx
  520.         cmp     ecx,[sel.end.y]
  521.         je      @f
  522.         mov     eax,esi
  523.         call    get_line_offset
  524.         sub     eax,esi
  525.         mov     ecx,eax
  526.         rep     movsb
  527.         mov     ecx,[sel.end.y]
  528.     @@: call    get_line_offset
  529.         mov     eax,[esi+EDITOR_LINE_DATA.Size]
  530.         add     esi,sizeof.EDITOR_LINE_DATA
  531.         cmp     eax,[sel.end.x]
  532.         jle     @f
  533.         mov     eax,[sel.end.x]
  534.     @@: mov     ebx,edi
  535.         mov     [edi+EDITOR_LINE_DATA.Size],eax
  536.         add     edi,sizeof.EDITOR_LINE_DATA
  537.         mov     ecx,eax
  538.         jecxz   @f
  539.         rep     movsb
  540.         sub     eax,[sel.end.x]
  541.         jz      @f
  542.         neg     eax
  543.         mov     ecx,eax
  544.         add     [ebx],eax
  545.         mov     al,' '
  546.         rep     stosb
  547.     @@: sub     edi,[copy_buf]
  548.         mov     [copy_size],edi
  549.         mov     eax,[sel.end.y]
  550.         sub     eax,[sel.begin.y]
  551.         inc     eax
  552.         mov     [copy_count],eax
  553.         call    put_to_clipboard
  554.   .exit:
  555.         ret
  556.  
  557.   .single_line:
  558.         mov     eax,[sel.end.x]
  559.         sub     eax,[sel.begin.x]
  560.         mov     edi,[copy_buf]
  561.         mov     [edi+EDITOR_LINE_DATA.Size],eax
  562.         add     edi,sizeof.EDITOR_LINE_DATA
  563.         mov     ecx,[sel.begin.y]
  564.         call    get_line_offset
  565.         mov     ebx,[sel.begin.x]
  566.         mov     ecx,[sel.end.x]
  567.         cmp     ebx,[esi+EDITOR_LINE_DATA.Size]
  568.         jge     .add_spaces
  569.         cmp     ecx,[esi+EDITOR_LINE_DATA.Size]
  570.         jle     .lp1
  571.         mov     ecx,[esi+EDITOR_LINE_DATA.Size]
  572.   .lp1: sub     ecx,[sel.begin.x]
  573.         sub     eax,ecx
  574.         lea     esi,[esi+ebx+sizeof.EDITOR_LINE_DATA]
  575.         rep     movsb
  576.  
  577.   .add_spaces:
  578.         mov     ecx,eax
  579.         mov     al,' '
  580.         jecxz   @b
  581.         rep     stosb
  582.         jmp     @b
  583. endp
  584.  
  585. ;-----------------------------------------------------------------------------
  586. proc key.ctrl_v
  587.         cmp     [replace_mode],0
  588.         jne     @f
  589.         call    get_from_clipboard
  590. @@:
  591.         cmp     [copy_size],0
  592.         je      .exit_1
  593.         call    delete_selection
  594.         mov     eax,[copy_size]
  595.         sub     eax,sizeof.EDITOR_LINE_DATA
  596.         call    editor_realloc_lines
  597.         mov     ecx,[cur_editor.Caret.Y]
  598.         call    get_line_offset
  599.         mov     ecx,[cur_editor.Caret.X]
  600.         call    line_add_spaces
  601.         pushd   [esi+EDITOR_LINE_DATA.Size]
  602.         push    esi
  603.         lea     eax,[esi+ecx+sizeof.EDITOR_LINE_DATA]
  604.         mov     edi,[cur_editor.Lines]
  605.         add     edi,[cur_editor.Lines.Size]
  606.         dec     edi
  607.         mov     ecx,[copy_size]
  608.         sub     ecx,sizeof.EDITOR_LINE_DATA
  609.         mov     esi,edi
  610.         sub     esi,ecx
  611.         neg     eax
  612.         lea     ecx,[esi+eax+1]
  613.         std
  614.         rep     movsb
  615.         cld
  616.         pop     edi
  617.         mov     esi,[copy_buf]
  618.         mov     eax,[esi+EDITOR_LINE_DATA.Size]
  619.         add     esi,sizeof.EDITOR_LINE_DATA
  620.         mov     ecx,[copy_count]
  621.         dec     ecx
  622.         jz      .single_line
  623.  
  624.         add     eax,[cur_editor.Caret.X]
  625.         mov     [edi+EDITOR_LINE_DATA.Size],eax
  626.         mov     [edi+EDITOR_LINE_DATA.Flags],EDITOR_LINE_FLAG_MOFIFIED
  627.         sub     eax,[cur_editor.Caret.X]
  628.         call    .check_columns
  629.         add     edi,[cur_editor.Caret.X]
  630. @@:
  631.         push    ecx
  632.         mov     ecx,eax
  633.         add     edi,sizeof.EDITOR_LINE_DATA
  634.         rep     movsb
  635.         mov     eax,[esi+EDITOR_LINE_DATA.Size]
  636.         add     esi,sizeof.EDITOR_LINE_DATA
  637.         mov     [edi+EDITOR_LINE_DATA.Size],eax
  638.         mov     [edi+EDITOR_LINE_DATA.Flags],EDITOR_LINE_FLAG_MOFIFIED
  639.         pop     ecx
  640.         loop    @b
  641.  
  642.         pop     ecx
  643.         sub     ecx,[cur_editor.Caret.X]
  644.         add     [edi+EDITOR_LINE_DATA.Size],ecx
  645.         call    .check_columns
  646.         add     edi,sizeof.EDITOR_LINE_DATA
  647.         mov     ecx,eax
  648.         rep     movsb
  649. .save_cur_editor_values:
  650.         mov     [cur_editor.Caret.X],eax
  651.         mov     [cur_editor.SelStart.X],eax
  652.         mov     eax,[copy_count]
  653.         dec     eax
  654.         add     [cur_editor.Caret.Y],eax
  655.         add     [cur_editor.SelStart.Y],eax
  656.         add     [cur_editor.Lines.Count],eax
  657.         mov     [cur_editor.Modified],1
  658.         jmp     .exit
  659.  
  660. .single_line:
  661.         add     [edi+EDITOR_LINE_DATA.Size],eax
  662.         mov     [edi+EDITOR_LINE_DATA.Flags],EDITOR_LINE_FLAG_MOFIFIED
  663.         call    .check_columns
  664.         add     edi,sizeof.EDITOR_LINE_DATA
  665.         add     edi,[cur_editor.Caret.X]
  666.         pop     ecx
  667.         mov     ecx,eax
  668.         rep     movsb
  669.         add     [cur_editor.Caret.X],eax
  670.         add     [cur_editor.SelStart.X],eax
  671.         mov     [cur_editor.Modified],1
  672. .exit:
  673.         cmp     [replace_mode],0
  674.         jne     .exit_1
  675.         stdcall mem.Free,[copy_buf]
  676.         xor     eax,eax
  677.         mov     [copy_buf],eax
  678.         mov     [copy_size],eax
  679.         mov     [copy_count],eax
  680. .exit_1:
  681.         ret
  682.  
  683. .check_columns:
  684.         push    eax
  685.         mov     eax,[edi+EDITOR_LINE_DATA.Size]
  686.         cmp     eax,[cur_editor.Columns.Count]
  687.         jbe     @f
  688.         mov     [cur_editor.Columns.Count],eax
  689. @@:
  690.         pop     eax
  691.         ret
  692. endp
  693. ;-----------------------------------------------------------------------------
  694. proc key.ctrl_d ;///// INSERT SEPARATOR //////////////////////////////////////
  695. ;-----------------------------------------------------------------------------
  696.         mov     eax,90+sizeof.EDITOR_LINE_DATA
  697.         call    editor_realloc_lines
  698.  
  699.         mov     ecx,[cur_editor.Caret.Y]
  700.         call    get_line_offset
  701.         mov     ebx,esi
  702.  
  703.         mov     ecx,[cur_editor.Lines.Count]
  704.         call    get_line_offset
  705.         lea     edi,[esi+90+sizeof.EDITOR_LINE_DATA]
  706.         lea     ecx,[esi+sizeof.EDITOR_LINE_DATA]
  707.         sub     ecx,ebx
  708.         std
  709.         rep     movsb
  710.  
  711.         lea     edi,[ebx+sizeof.EDITOR_LINE_DATA+1]
  712.         mov     [ebx+EDITOR_LINE_DATA.Size],90
  713.         mov     al,ASEPC
  714.         mov     ecx,79
  715.         cld
  716.         rep     stosb
  717.         mov     al,' '
  718.         mov     ecx,10
  719.         rep     stosb
  720.         mov     byte[ebx+sizeof.EDITOR_LINE_DATA],';'
  721.  
  722.         inc     [cur_editor.Lines.Count]
  723.         inc     [cur_editor.Caret.Y]
  724.         m2m     [cur_editor.SelStart.Y],[cur_editor.Caret.Y]
  725.  
  726.         mov     [cur_editor.Modified],1
  727.  
  728.   .exit:
  729.         ret
  730. endp
  731.  
  732. ;-----------------------------------------------------------------------------
  733. proc key.ctrl_y ;///// DELETE CURRENT LINE ///////////////////////////////////
  734. ;-----------------------------------------------------------------------------
  735.         mov     eax,[cur_editor.Caret.Y]
  736.         inc     eax
  737.         cmp     eax,[cur_editor.Lines.Count]
  738.         jge     .exit
  739.  
  740.         mov     ecx,[cur_editor.Caret.Y]
  741.         call    get_line_offset
  742.         mov     edi,esi
  743.         mov     eax,[esi+EDITOR_LINE_DATA.Size]
  744.         lea     esi,[esi+eax+sizeof.EDITOR_LINE_DATA]
  745.         push    eax
  746.  
  747.         dec     [cur_editor.Lines.Count]
  748.         mov     ecx,[cur_editor.Lines]
  749.         add     ecx,[cur_editor.Lines.Size] ;*** add ecx,[ecx-4]
  750.         sub     ecx,esi
  751.         shr     ecx,2
  752.         cld
  753.         rep     movsd
  754.  
  755.         pop     eax
  756.         add     eax,sizeof.EDITOR_LINE_DATA
  757.         neg     eax
  758.         call    editor_realloc_lines
  759.  
  760.         m2m     [cur_editor.SelStart.X],[cur_editor.Caret.X]
  761.         m2m     [cur_editor.SelStart.Y],[cur_editor.Caret.Y]
  762.  
  763.         mov     [cur_editor.Modified],1
  764.  
  765.   .exit:
  766.         ret
  767. endp
  768.  
  769. ;-----------------------------------------------------------------------------
  770. proc key.up ;///// GO TO PREVIOUS LINE ///////////////////////////////////////
  771. ;-----------------------------------------------------------------------------
  772.         call    key.shift_up
  773.         jmp     clear_selection
  774. ;-----------------------------------------------------------------------------
  775.      key.shift_up: ;///// GO TO PREVIOUS LINE, WITH SELECTION ////////////////
  776. ;-----------------------------------------------------------------------------
  777.         mov     ecx,[cur_editor.Caret.Y]
  778.         dec     ecx
  779.         js      .exit
  780.         mov     [cur_editor.Caret.Y],ecx
  781.         call    get_line_offset
  782.         mov     eax,[esi]
  783.         cmp     eax,[cur_editor.Caret.X]
  784.         jnc     .exit
  785.         mov     [cur_editor.Caret.X],eax
  786. .exit:
  787.         ret
  788. endp
  789.  
  790. ;-----------------------------------------------------------------------------
  791. proc key.down ;///// GO TO NEXT LINE /////////////////////////////////////////
  792. ;-----------------------------------------------------------------------------
  793.         call    key.shift_down
  794.         jmp     clear_selection
  795. ;-----------------------------------------------------------------------------
  796.      key.shift_down: ;///// GO TO NEXT LINE, WITH SELECTION //////////////////
  797. ;-----------------------------------------------------------------------------
  798.         mov     ecx,[cur_editor.Caret.Y]
  799.         inc     ecx
  800.         cmp     [cur_editor.Lines.Count],ecx
  801.         jz      .exit
  802.         mov     [cur_editor.Caret.Y],ecx
  803.         call    get_line_offset
  804.         mov     eax,[esi]
  805.         cmp     eax,[cur_editor.Caret.X]
  806.         jnc     .exit
  807.         mov     [cur_editor.Caret.X],eax
  808. .exit:
  809.         ret
  810. endp
  811.  
  812. ;-----------------------------------------------------------------------------
  813. proc key.left ;///// GO TO PREVIOUS CHAR /////////////////////////////////////
  814. ;-----------------------------------------------------------------------------
  815.         call    key.shift_left
  816.         jmp     clear_selection
  817. ;-----------------------------------------------------------------------------
  818.      key.shift_left: ;///// GO TO PREVIOUS CHAR, WITH SELECTION //////////////
  819. ;-----------------------------------------------------------------------------
  820.         mov     eax,[cur_editor.Caret.X]
  821.         dec     eax
  822.         jns     @f
  823.         mov     ecx,[cur_editor.Caret.Y]
  824.         dec     ecx
  825.         js      .exit
  826.         mov     [cur_editor.Caret.Y],ecx
  827.         call    get_line_offset
  828.         mov     eax,[esi]
  829. @@:
  830.         mov     [cur_editor.Caret.X],eax
  831. .exit:
  832.         ret
  833. endp
  834.  
  835. ;-----------------------------------------------------------------------------
  836. proc key.right ;///// GO TO NEXT CHAR ////////////////////////////////////////
  837. ;-----------------------------------------------------------------------------
  838.         call    key.shift_right
  839.         jmp     clear_selection
  840. ;-----------------------------------------------------------------------------
  841.      key.shift_right: ;///// GO TO NEXT CHAR, WITH SELECTION /////////////////
  842. ;-----------------------------------------------------------------------------
  843.         mov     ecx,[cur_editor.Caret.Y]
  844.         call    get_line_offset
  845.         mov     eax,[cur_editor.Caret.X]
  846.         inc     eax
  847.         cmp     [esi],eax
  848.         jnc     @f
  849.         inc     ecx
  850.         cmp     [cur_editor.Lines.Count],ecx
  851.         jz      .exit
  852.         xor     eax,eax
  853.         mov     [cur_editor.Caret.Y],ecx
  854. @@:
  855.         mov     [cur_editor.Caret.X],eax
  856. .exit:
  857.         ret
  858. endp
  859.  
  860. ;-----------------------------------------------------------------------------
  861. proc key.pgup ;///// GO TO PREVIOUS PAGE /////////////////////////////////////
  862. ;-----------------------------------------------------------------------------
  863.         call    clear_selection
  864.  
  865. ;-----------------------------------------------------------------------------
  866.      key.shift_pgup: ;///// GO TO PREVIOUS PAGE, WITH SELECTION //////////////
  867. ;-----------------------------------------------------------------------------
  868.         mov     edx,[lines.scr]
  869.         dec     edx
  870.         mov     eax,[cur_editor.Caret.Y]
  871.         mov     ecx,[cur_editor.TopLeft.Y]
  872.         sub     eax,edx
  873.         jns     @f
  874.         xor     eax,eax
  875.     @@: sub     ecx,edx
  876.         jns     @f
  877.         xor     ecx,ecx
  878.     @@: test    [chr],KM_SHIFT
  879.         jnz     @f
  880.         mov     [cur_editor.SelStart.Y],eax
  881.     @@: mov     [cur_editor.Caret.Y],eax
  882.         mov     [cur_editor.TopLeft.Y],ecx
  883.  
  884.   .exit:
  885.         ret
  886. endp
  887.  
  888. ;-----------------------------------------------------------------------------
  889. proc key.pgdn ;///// GO TO NEXT PAGE /////////////////////////////////////////
  890. ;-----------------------------------------------------------------------------
  891.         call    clear_selection
  892.  
  893. ;-----------------------------------------------------------------------------
  894.      key.shift_pgdn: ;///// GO TO NEXT PAGE, WITH SELECTION //////////////////
  895. ;-----------------------------------------------------------------------------
  896.         mov     edx,[lines.scr]
  897.         dec     edx
  898.         mov     eax,[cur_editor.Caret.Y]
  899.         mov     ecx,[cur_editor.TopLeft.Y]
  900.         add     eax,edx
  901.         add     ecx,edx
  902.         cmp     eax,[cur_editor.Lines.Count]
  903.         jb      @f
  904.         mov     eax,[cur_editor.Lines.Count]
  905.         dec     eax
  906.     @@: test    [chr],KM_SHIFT
  907.         jnz     @f
  908.         mov     [cur_editor.SelStart.Y],eax
  909.     @@: mov     [cur_editor.Caret.Y],eax
  910.         mov     [cur_editor.TopLeft.Y],ecx
  911.  
  912.   .exit:
  913.         ret
  914. endp
  915.  
  916. ;-----------------------------------------------------------------------------
  917. proc key.home ;///// GO TO LINE START ////////////////////////////////////////
  918. ;-----------------------------------------------------------------------------
  919.         call    clear_selection
  920.  
  921. ;-----------------------------------------------------------------------------
  922.      key.shift_home: ;///// GO TO LINE START, WITH SELECTION /////////////////
  923. ;-----------------------------------------------------------------------------
  924.         mov     [cur_editor.Caret.X],0
  925.         test    [chr],KM_SHIFT
  926.         jnz     @f
  927.         mov     [cur_editor.SelStart.X],0
  928.     @@:
  929.  
  930.   .exit:
  931.         ret
  932. endp
  933.  
  934. ;-----------------------------------------------------------------------------
  935. proc key.end ;///// GO TO LINE END ///////////////////////////////////////////
  936. ;-----------------------------------------------------------------------------
  937.         call    clear_selection
  938.  
  939. ;-----------------------------------------------------------------------------
  940.      key.shift_end: ;///// GO TO LINE END, WITH SELECTION ////////////////////
  941. ;-----------------------------------------------------------------------------
  942.         mov     ecx,[cur_editor.Caret.Y]
  943.         call    get_line_offset
  944.         call    get_real_length
  945.         mov     [cur_editor.Caret.X],eax
  946.         test    [chr],KM_SHIFT
  947.         jnz     @f
  948.         mov     [cur_editor.SelStart.X],eax
  949.     @@:
  950.  
  951.   .exit:
  952.         ret
  953. endp
  954.  
  955. ;-----------------------------------------------------------------------------
  956. proc key.ctrl_home ;///// GO TO PAGE START ///////////////////////////////////
  957. ;-----------------------------------------------------------------------------
  958.         call    clear_selection
  959.  
  960. ;-----------------------------------------------------------------------------
  961.      key.shift_ctrl_home: ;///// GO TO PAGE START, WITH SELECTION ////////////
  962. ;-----------------------------------------------------------------------------
  963.         mov     eax,[cur_editor.TopLeft.Y]
  964.         mov     ecx,eax
  965.         test    [chr],KM_SHIFT
  966.         jnz     @f
  967.         mov     [cur_editor.SelStart.Y],eax
  968.     @@: mov     [cur_editor.Caret.Y],eax
  969.         mov     [cur_editor.TopLeft.Y],ecx
  970.  
  971.   .exit:
  972.         ret
  973. endp
  974.  
  975. ;-----------------------------------------------------------------------------
  976. proc key.ctrl_end ;///// GO TO PAGE END //////////////////////////////////////
  977. ;-----------------------------------------------------------------------------
  978.         call    clear_selection
  979.  
  980. ;-----------------------------------------------------------------------------
  981.      key.shift_ctrl_end: ;///// GO TO PAGE END, WITH SELECTION ///////////////
  982. ;-----------------------------------------------------------------------------
  983.         mov     ecx,[cur_editor.TopLeft.Y]
  984.         mov     eax,[lines.scr]
  985.         cmp     eax,[cur_editor.Lines.Count]
  986.         jle     @f
  987.         mov     eax,[cur_editor.Lines.Count]
  988.     @@: add     eax,ecx
  989.         dec     eax
  990.         test    [chr],KM_SHIFT
  991.         jnz     @f
  992.         mov     [cur_editor.SelStart.Y],eax
  993.     @@: mov     [cur_editor.Caret.Y],eax
  994.         mov     [cur_editor.TopLeft.Y],ecx
  995.  
  996.   .exit:
  997.         ret
  998. endp
  999.  
  1000. ;-----------------------------------------------------------------------------
  1001. proc key.ctrl_pgup ;///// GO TO DOCUMENT START ///////////////////////////////
  1002. ;-----------------------------------------------------------------------------
  1003.         call    clear_selection
  1004.  
  1005. ;-----------------------------------------------------------------------------
  1006.      key.shift_ctrl_pgup: ;///// GO TO DOCUMENT START, WITH SELECTION ////////
  1007. ;-----------------------------------------------------------------------------
  1008.         xor     eax,eax
  1009.         mov     [cur_editor.TopLeft.Y],eax
  1010.         mov     [cur_editor.Caret.Y],eax
  1011.         test    [chr],KM_SHIFT
  1012.         jnz     @f
  1013.         mov     [cur_editor.SelStart.Y],eax
  1014.     @@:
  1015.  
  1016.   .exit:
  1017.         ret
  1018. endp
  1019.  
  1020. ;-----------------------------------------------------------------------------
  1021. proc key.ctrl_pgdn ;///// GO TO DOCUMENT END /////////////////////////////////
  1022. ;-----------------------------------------------------------------------------
  1023.         call    clear_selection
  1024.  
  1025. ;-----------------------------------------------------------------------------
  1026.      key.shift_ctrl_pgdn: ;///// GO TO DOCUMENT END, WITH SELECTION //////////
  1027. ;-----------------------------------------------------------------------------
  1028.         mov     eax,[cur_editor.Lines.Count]
  1029.         mov     [cur_editor.Caret.Y],eax
  1030.         sub     eax,[lines.scr]
  1031.         jns     @f
  1032.         xor     eax,eax
  1033.     @@: mov     [cur_editor.TopLeft.Y],eax
  1034.         dec     [cur_editor.Caret.Y]
  1035.         test    [chr],KM_SHIFT
  1036.         jnz     @f
  1037.         m2m     [cur_editor.SelStart.Y],[cur_editor.Caret.Y]
  1038.     @@:
  1039.  
  1040.   .exit:
  1041.         ret
  1042. endp
  1043.  
  1044. ;-----------------------------------------------------------------------------
  1045. proc key.del ;///// DELETE NEXT CHAR OR SELECTION ////////////////////////////
  1046. ;-----------------------------------------------------------------------------
  1047.         call    delete_selection
  1048.         jnc     .exit
  1049.  
  1050.         mov     ecx,[cur_editor.Caret.Y]
  1051.         call    get_line_offset
  1052.         and     [esi+EDITOR_LINE_DATA.Flags],not EDITOR_LINE_FLAG_SAVED
  1053.         or      [esi+EDITOR_LINE_DATA.Flags],EDITOR_LINE_FLAG_MOFIFIED
  1054.         lea     ebx,[esi+sizeof.EDITOR_LINE_DATA]
  1055.         mov     ebp,esi
  1056.  
  1057.         call    get_real_length
  1058.         or      eax,eax
  1059.         je      .line_up
  1060.  
  1061.         mov     ecx,[cur_editor.Caret.X]
  1062.         cmp     ecx,eax
  1063.         jae     .line_up
  1064.         lea     edi,[ebx+ecx]
  1065.         neg     ecx
  1066.         mov     eax,[ebp+EDITOR_LINE_DATA.Size]
  1067.         add     ecx,eax;[ebp]
  1068.         repe    scasb
  1069.         je      .line_up
  1070.  
  1071.         mov     edi,ebx
  1072.         mov     ecx,[cur_editor.Caret.X]
  1073.         add     edi,ecx
  1074.         lea     esi,[edi+1]
  1075.         neg     ecx
  1076.         mov     eax,[ebp+EDITOR_LINE_DATA.Size]
  1077.         add     ecx,eax;[ebp]
  1078.         dec     ecx
  1079.         rep     movsb
  1080.         mov     byte[edi],' '
  1081.  
  1082.         m2m     [cur_editor.SelStart.X],[cur_editor.Caret.X]
  1083.         m2m     [cur_editor.SelStart.Y],[cur_editor.Caret.Y]
  1084.         mov     [cur_editor.Modified],1
  1085.         ret
  1086.  
  1087.   .line_up:
  1088.         mov     eax,[cur_editor.Lines.Count]
  1089.         dec     eax
  1090.         cmp     eax,[cur_editor.Caret.Y]
  1091.         je      .exit
  1092.         mov     edi,[temp_buf]
  1093.         add     edi,sizeof.EDITOR_LINE_DATA
  1094.         mov     esi,ebx
  1095.         mov     ecx,[cur_editor.Caret.X]
  1096.         rep     movsb
  1097.         mov     ecx,[cur_editor.Caret.X]
  1098.         mov     eax,[temp_buf]
  1099.         mov     [eax+EDITOR_LINE_DATA.Size],ecx
  1100.         cmp     ecx,[ebp+EDITOR_LINE_DATA.Size]
  1101.         jbe     @f
  1102.         mov     eax,[ebp+EDITOR_LINE_DATA.Size]
  1103.         sub     ecx,eax
  1104.         sub     edi,ecx
  1105.         mov     al,' '
  1106.         rep     stosb
  1107.     @@: lea     esi,[ebx+sizeof.EDITOR_LINE_DATA]
  1108.         mov     eax,[ebp+EDITOR_LINE_DATA.Size]
  1109.         add     esi,eax
  1110.         mov     ecx,[esi-sizeof.EDITOR_LINE_DATA+EDITOR_LINE_DATA.Size]
  1111.         mov     eax,[temp_buf]
  1112.         add     [eax+EDITOR_LINE_DATA.Size],ecx
  1113.         or      [eax+EDITOR_LINE_DATA.Flags],EDITOR_LINE_FLAG_MOFIFIED
  1114.         rep     movsb
  1115.  
  1116.         mov     ecx,edi
  1117.         sub     ecx,[temp_buf]
  1118.  
  1119.         mov     esi,[temp_buf]
  1120.         call    get_real_length
  1121.         cmp     eax,[cur_editor.Columns.Count]
  1122.         jbe     @f
  1123.         mov     [cur_editor.Columns.Count],eax
  1124.     @@:
  1125.         push    ecx
  1126.         mov     edi,[cur_editor.Lines]
  1127.         add     edi,[cur_editor.Lines.Size] ;*** add edi,[edi-4]
  1128.         dec     edi
  1129.         lea     esi,[edi+sizeof.EDITOR_LINE_DATA*2] ; !!! CHECK THIS !!!
  1130.         sub     esi,ecx
  1131.         mov     eax,[ebp+EDITOR_LINE_DATA.Size]
  1132.         add     esi,eax
  1133.         mov     eax,[ebp+eax+sizeof.EDITOR_LINE_DATA+EDITOR_LINE_DATA.Size]
  1134.         add     esi,eax
  1135.         lea     ecx,[esi-sizeof.EDITOR_LINE_DATA]
  1136.         sub     ecx,ebp
  1137.         std
  1138.         cmp     esi,edi
  1139.         jb      @f
  1140.         jz      .lp1
  1141.         mov     edi,ebp
  1142.         add     edi,[esp]
  1143.         lea     esi,[ebp+sizeof.EDITOR_LINE_DATA*2] ; !!! CHECK THIS !!!
  1144.         mov     eax,[esi-sizeof.EDITOR_LINE_DATA*2+EDITOR_LINE_DATA.Size] ; !!! CHECK THIS !!!
  1145.         add     esi,eax
  1146.         mov     eax,[esi-sizeof.EDITOR_LINE_DATA+EDITOR_LINE_DATA.Size] ; !!! CHECK THIS !!!
  1147.         add     esi,eax
  1148.         mov     ecx,[cur_editor.Lines]
  1149.         add     ecx,[cur_editor.Lines.Size] ;*** add ecx,[ecx-4]
  1150.         sub     ecx,esi
  1151.         cld
  1152.     @@: rep     movsb
  1153.   .lp1: pop     ecx
  1154.         mov     esi,[temp_buf]
  1155.         mov     edi,ebp
  1156.         cld
  1157.         rep     movsb
  1158.  
  1159.   .ok.dec.lines:
  1160.         dec     [cur_editor.Lines.Count]
  1161.         mov     eax,[cur_editor.Lines.Count]
  1162.         cmp     [cur_editor.Caret.Y],eax
  1163.         jb      @f
  1164.         dec     eax
  1165.         mov     [cur_editor.Caret.Y],eax
  1166.     @@: m2m     [cur_editor.SelStart.X],[cur_editor.Caret.X]
  1167.         m2m     [cur_editor.SelStart.Y],[cur_editor.Caret.Y]
  1168.  
  1169.         mov     ecx,[cur_editor.Lines.Count]
  1170.         call    get_line_offset
  1171.         mov     eax,[esi+EDITOR_LINE_DATA.Size]
  1172.         lea     esi,[esi+eax+sizeof.EDITOR_LINE_DATA]
  1173.         mov     eax,[cur_editor.Lines]
  1174.         add     eax,[cur_editor.Lines.Size] ;*** add eax,[eax-4]
  1175.         sub     esi,eax
  1176.         lea     eax,[esi+4096]
  1177.         call    editor_realloc_lines
  1178.  
  1179.         mov     [cur_editor.Modified],1
  1180.  
  1181.   .exit:
  1182.         ret
  1183. endp
  1184.  
  1185. ;-----------------------------------------------------------------------------
  1186. proc key.ins ;///// TOGGLE INSERT/OVERWRITE MODE /////////////////////////////
  1187. ;-----------------------------------------------------------------------------
  1188.         xor     [ins_mode],1
  1189.         mov     eax,[cur_editor.Caret.Y]
  1190.         mov     ebx,eax
  1191.         call    draw_editor_text.part
  1192.         call    draw_editor_caret
  1193.         ret
  1194. endp
  1195.  
  1196. ;-----------------------------------------------------------------------------
  1197. proc key.bkspace ;///// DELETE PREVIOUS CHAR OR SELECTION ////////////////////
  1198. ;-----------------------------------------------------------------------------
  1199.         call    delete_selection
  1200.         jnc     key.del.exit
  1201.  
  1202.         mov     eax,[cur_editor.Caret.X]
  1203.         dec     eax
  1204.         js      .line_up
  1205.  
  1206.         dec     [cur_editor.Caret.X]
  1207.         mov     ecx,[cur_editor.Caret.Y]
  1208.         call    get_line_offset
  1209.         and     [esi+EDITOR_LINE_DATA.Flags],not EDITOR_LINE_FLAG_SAVED
  1210.         or      [esi+EDITOR_LINE_DATA.Flags],EDITOR_LINE_FLAG_MOFIFIED
  1211.  
  1212.         mov     ebx,eax
  1213.         call    get_real_length
  1214.         cmp     eax,[cur_editor.Caret.X]
  1215.         jae     @f
  1216.         m2m     [cur_editor.SelStart.X],[cur_editor.Caret.X]
  1217.         mov     [cur_editor.Modified],1
  1218.         ret
  1219.  
  1220.     @@: lea     edi,[esi+sizeof.EDITOR_LINE_DATA+ebx]
  1221.         mov     ecx,ebx
  1222.         neg     ecx
  1223.         mov     eax,[esi+EDITOR_LINE_DATA.Size]
  1224.         add     ecx,eax
  1225.         dec     ecx
  1226.         lea     esi,[edi+1]
  1227.         cld
  1228.         rep     movsb
  1229.         mov     byte[edi],' '
  1230.  
  1231.         m2m     [cur_editor.SelStart.X],[cur_editor.Caret.X]
  1232.         m2m     [cur_editor.SelStart.Y],[cur_editor.Caret.Y]
  1233.         mov     [cur_editor.Modified],1
  1234.         ret
  1235.  
  1236.   .line_up:
  1237.         cmp     [cur_editor.Caret.Y],0
  1238.         jne     @f
  1239.         ret
  1240.     @@: mov     ecx,[cur_editor.Caret.Y]
  1241.         dec     ecx
  1242.         call    get_line_offset
  1243.         and     [esi+EDITOR_LINE_DATA.Flags],not EDITOR_LINE_FLAG_SAVED
  1244.         or      [esi+EDITOR_LINE_DATA.Flags],EDITOR_LINE_FLAG_MOFIFIED
  1245.  
  1246.         mov     ebp,esi
  1247.         lea     ebx,[esi+sizeof.EDITOR_LINE_DATA]
  1248.         mov     ecx,[ebp+EDITOR_LINE_DATA.Size]
  1249.     @@: cmp     byte[ebx+ecx-1],' '
  1250.         jne     @f
  1251.         dec     ecx
  1252.         jg      @b
  1253.     @@: mov     [cur_editor.Caret.X],ecx
  1254.         dec     [cur_editor.Caret.Y]
  1255.         cld
  1256.         jmp     key.del.line_up
  1257. endp
  1258.  
  1259. ;-----------------------------------------------------------------------------
  1260. proc key.tab ;///// TABULATE /////////////////////////////////////////////////
  1261. ;-----------------------------------------------------------------------------
  1262.         call    delete_selection
  1263.         mov     eax,[cur_editor.Caret.X]
  1264.  
  1265.         mov     ecx,eax
  1266.         add     eax,ATABW
  1267.         and     eax,not(ATABW-1)
  1268.         push    eax ' '
  1269.         sub     eax,ecx
  1270.   .direct:
  1271.         push    eax
  1272.         call    editor_realloc_lines
  1273.         pop     eax
  1274.         mov     ecx,[cur_editor.Caret.Y]
  1275.         call    get_line_offset
  1276.         and     [esi+EDITOR_LINE_DATA.Flags],not EDITOR_LINE_FLAG_SAVED
  1277.         or      [esi+EDITOR_LINE_DATA.Flags],EDITOR_LINE_FLAG_MOFIFIED
  1278.  
  1279.         xchg    eax,ecx
  1280.  
  1281.         call    get_real_length
  1282.         cmp     eax,[cur_editor.Caret.X]
  1283.         jae     @f
  1284.         mov     eax,[cur_editor.Caret.X]
  1285.     @@: mov     edx,[esi+EDITOR_LINE_DATA.Size]
  1286.         sub     edx,eax
  1287.         cmp     ecx,edx
  1288.         jl      @f
  1289.         push    eax
  1290.         mov     eax,10
  1291.         call    editor_realloc_lines
  1292.         add     esi,eax
  1293.         pop     eax
  1294.         pushad
  1295.         mov     ecx,[cur_editor.Lines]
  1296.         add     ecx,[cur_editor.Lines.Size] ;*** add ecx,[ecx-4]
  1297.         dec     ecx
  1298.         mov     edi,ecx
  1299.         add     ecx,-10+1
  1300.         mov     eax,[esi+EDITOR_LINE_DATA.Size]
  1301.         lea     eax,[esi+eax+sizeof.EDITOR_LINE_DATA]
  1302.         sub     ecx,eax
  1303.         lea     esi,[edi-10]
  1304.         std
  1305.         rep     movsb
  1306.         mov     ecx,10
  1307.         mov     al,' '
  1308.         rep     stosb
  1309.         popad
  1310.         add     [esi+EDITOR_LINE_DATA.Size],10
  1311.         jmp     @b
  1312.     @@: lea     ebx,[esi+sizeof.EDITOR_LINE_DATA]
  1313.         push    ecx
  1314.         mov     edi,[esi+EDITOR_LINE_DATA.Size]
  1315.         lea     edi,[ebx+edi-1]
  1316.         mov     esi,edi
  1317.         sub     esi,ecx
  1318.         lea     ecx,[esi+1]
  1319.         sub     ecx,ebx
  1320.         sub     ecx,[cur_editor.Caret.X]
  1321.         std
  1322.         rep     movsb
  1323.   .ok:  pop     ecx
  1324.         pop     eax
  1325.         rep     stosb
  1326.         cld
  1327.         pop     [cur_editor.Caret.X]
  1328.         lea     esi,[ebx-sizeof.EDITOR_LINE_DATA]
  1329.         call    get_real_length
  1330.         cmp     eax,[cur_editor.Caret.X]
  1331.         jae     @f
  1332.         mov     eax,[cur_editor.Caret.X]
  1333.     @@: cmp     eax,[cur_editor.Columns.Count]
  1334.         jbe     @f
  1335.         mov     [cur_editor.Columns.Count],eax
  1336.     @@: m2m     [cur_editor.SelStart.X],[cur_editor.Caret.X]
  1337.         m2m     [cur_editor.SelStart.Y],[cur_editor.Caret.Y]
  1338.         mov     [cur_editor.Modified],1
  1339.  
  1340.   .exit:
  1341.         ret
  1342. endp
  1343.  
  1344. ;-----------------------------------------------------------------------------
  1345. proc key.return ;///// CARRIAGE RETURN ///////////////////////////////////////
  1346. ;-----------------------------------------------------------------------------
  1347.         call    delete_selection
  1348. ; unknown how many times the user wants to press "Enter",
  1349. ; so you should do a little more value
  1350.         mov     eax,14*100
  1351.         call    editor_realloc_lines
  1352.  
  1353.         mov     ecx,[cur_editor.Caret.Y]
  1354.         call    get_line_offset
  1355.  
  1356.         mov     ebx,[cur_editor.Caret.X]
  1357.         cmp     ebx,[esi+EDITOR_LINE_DATA.Size]
  1358.         jb      @f
  1359.         mov     ebx,[esi+EDITOR_LINE_DATA.Size]
  1360.         dec     ebx
  1361.         jns     @f
  1362.         xor     ebx,ebx
  1363.     @@:
  1364.         cld
  1365.  
  1366.         mov     edi,[temp_buf]
  1367.         mov     ebp,esi
  1368.         lea     ecx,[ebx+1]
  1369.     @@: dec     ecx
  1370.         jz      @f
  1371.         cmp     byte[esi+ecx+sizeof.EDITOR_LINE_DATA-1],' '
  1372.         je      @b
  1373.     @@: lea     eax,[ecx+10]
  1374.         mov     [edi+EDITOR_LINE_DATA.Size],eax
  1375.         mov     [edi+EDITOR_LINE_DATA.Flags],EDITOR_LINE_FLAG_MOFIFIED
  1376.         add     edi,sizeof.EDITOR_LINE_DATA
  1377.         jecxz   @f
  1378.         push    esi
  1379.         add     esi,sizeof.EDITOR_LINE_DATA
  1380.         rep     movsb
  1381.         pop     esi
  1382.     @@: mov     al,' '
  1383.         mov     ecx,10
  1384.         rep     stosb
  1385.  
  1386.         mov     ecx,[esi+EDITOR_LINE_DATA.Size]
  1387.         sub     ecx,ebx
  1388.         add     esi,ebx
  1389.         add     esi,sizeof.EDITOR_LINE_DATA
  1390.         inc     ecx
  1391.     @@: dec     ecx
  1392.         jz      @f
  1393.         cmp     byte[esi+ecx-1],' '
  1394.         je      @b
  1395.     @@: jz      .lp1
  1396.     @@: cmp     byte[esi],' '
  1397.         jne     .lp1
  1398.         inc     esi
  1399.         loop    @b
  1400.   .lp1: test    [auto_indent],1
  1401.         jz      .lp2
  1402.         push    edi ecx
  1403.         mov     ecx,[ebp+EDITOR_LINE_DATA.Size]
  1404.         lea     edi,[ebp+sizeof.EDITOR_LINE_DATA]
  1405.         mov     al,' '
  1406.         repe    scasb
  1407.         mov     eax,ecx
  1408.         pop     ecx edi
  1409.         je      .lp2
  1410.         neg     eax
  1411.         mov     edx,[ebp+EDITOR_LINE_DATA.Size]
  1412.         add     eax,edx;[ebp]
  1413.         dec     eax
  1414.         jmp     @f
  1415.   .lp2: xor     eax,eax
  1416.     @@: mov     edx,edi
  1417.         add     edi,sizeof.EDITOR_LINE_DATA
  1418.         mov     [cur_editor.Caret.X],eax
  1419.         jecxz   @f
  1420.         push    ecx
  1421.         mov     ecx,eax
  1422.         mov     al,' '
  1423.         rep     stosb
  1424.         pop     ecx
  1425.     @@: jecxz   @f
  1426.         rep     movsb
  1427.     @@: mov     ecx,10
  1428.         mov     al,' '
  1429.         rep     stosb
  1430.  
  1431.         lea     eax,[edi-sizeof.EDITOR_LINE_DATA]
  1432.         sub     eax,edx
  1433.         mov     [edx+EDITOR_LINE_DATA.Size],eax
  1434.         mov     [edx+EDITOR_LINE_DATA.Flags],EDITOR_LINE_FLAG_MOFIFIED
  1435.  
  1436.         mov     ecx,edi
  1437.         sub     ecx,[temp_buf]
  1438.  
  1439.         push    ecx
  1440.         mov     edi,[cur_editor.Lines]
  1441.         add     edi,[cur_editor.Lines.Size] ;*** add edi,[edi-4]
  1442.         dec     edi
  1443.         lea     esi,[edi+sizeof.EDITOR_LINE_DATA]
  1444.         sub     esi,ecx
  1445.         mov     ecx,[ebp+EDITOR_LINE_DATA.Size]
  1446.         add     esi,ecx
  1447.         lea     ecx,[esi-sizeof.EDITOR_LINE_DATA]
  1448.         sub     ecx,ebp
  1449.         std
  1450.         cmp     esi,edi
  1451.         jb      @f
  1452.         je      .lp3
  1453.         lea     esi,[ebp+sizeof.EDITOR_LINE_DATA]
  1454.         mov     eax,[esp]
  1455.         lea     edi,[esi+eax-sizeof.EDITOR_LINE_DATA]
  1456.         mov     ecx,[ebp+EDITOR_LINE_DATA.Size]
  1457.         add     esi,ecx
  1458.         mov     ecx,[cur_editor.Lines]
  1459.         add     ecx,[cur_editor.Lines.Size] ;*** add ecx,[ecx-4]
  1460.         sub     ecx,esi
  1461.         cld
  1462.     @@: rep     movsb
  1463.   .lp3: pop     ecx
  1464.         mov     esi,[temp_buf]
  1465.         mov     edi,ebp
  1466.         cld
  1467.         rep     movsb
  1468.  
  1469.         inc     [cur_editor.Caret.Y]
  1470.         inc     [cur_editor.SelStart.Y]
  1471.         inc     [cur_editor.Lines.Count]
  1472.  
  1473.         m2m     [cur_editor.SelStart.X],[cur_editor.Caret.X]
  1474.  
  1475.         mov     [cur_editor.Modified],1
  1476.  
  1477.   .exit:
  1478.         ret
  1479. endp
  1480.  
  1481. ;-----------------------------------------------------------------------------
  1482. proc key.ctrl_tab ;///// SWITCH TO NEXT TAB //////////////////////////////////
  1483. ;-----------------------------------------------------------------------------
  1484.         cmp     [tab_bar.Items.Count],1
  1485.         je      .exit
  1486.         xor     eax,eax
  1487.         mov     ebp,[tab_bar.Items]
  1488.     @@: cmp     ebp,[tab_bar.Current.Ptr]
  1489.         je      @f
  1490.         inc     eax
  1491.         add     ebp,sizeof.TABITEM
  1492.         jmp     @b
  1493.     @@: add     ebp,sizeof.TABITEM
  1494.         inc     eax
  1495.         cmp     eax,[tab_bar.Items.Count]
  1496.         jb      @f
  1497.         mov     ebp,[tab_bar.Items]
  1498.     @@: call    set_cur_tab
  1499.         call    make_tab_visible
  1500.         call    align_editor_in_tab
  1501.         call    draw_editor
  1502.         call    draw_tabctl
  1503.         call    update_caption
  1504.   .exit:
  1505.         ret
  1506. endp
  1507.  
  1508. ;-----------------------------------------------------------------------------
  1509. proc key.shift_ctrl_tab ;///// SWITCH TO PREVIOUS TAB ////////////////////////
  1510. ;-----------------------------------------------------------------------------
  1511.         cmp     [tab_bar.Items.Count],1
  1512.         je      .exit
  1513.         xor     eax,eax
  1514.         mov     ebp,[tab_bar.Items]
  1515.     @@: cmp     ebp,[tab_bar.Current.Ptr]
  1516.         je      @f
  1517.         inc     eax
  1518.         add     ebp,sizeof.TABITEM
  1519.         jmp     @b
  1520.     @@: add     ebp,-sizeof.TABITEM
  1521.         dec     eax
  1522.         jge     @f
  1523.         imul    eax,[tab_bar.Items.Count],sizeof.TABITEM
  1524.         add     eax,[tab_bar.Items]
  1525.         lea     ebp,[eax-sizeof.TABITEM]
  1526.     @@: call    set_cur_tab
  1527.         call    make_tab_visible
  1528.         call    align_editor_in_tab
  1529.         call    draw_editor
  1530.         call    draw_tabctl
  1531.         call    update_caption
  1532.   .exit:
  1533.         ret
  1534. endp
  1535.  
  1536. ;-----------------------------------------------------------------------------
  1537. proc key.ctrl_f4 ;///// CLOSE CURRENT TAB ////////////////////////////////////
  1538. ;-----------------------------------------------------------------------------
  1539.         cmp     [cur_editor.Modified],0
  1540.         je      .close
  1541.         mov     [bot_mode2],2
  1542.         jmp     key.ctrl_o.direct
  1543.  .close:
  1544.         mov     [do_not_draw],1
  1545.         push    [tab_bar.Current.Ptr]
  1546.         cmp     [tab_bar.Items.Count],1
  1547.         jne     @f
  1548.         ;call    create_tab
  1549.         jmp     key.alt_x.close         ; close program
  1550.     @@: pop     ebp
  1551.         call    delete_tab
  1552.         dec     [do_not_draw]
  1553.         call    align_editor_in_tab
  1554.         call    draw_editor
  1555.         call    draw_tabctl
  1556.         call    draw_statusbar
  1557.         ret
  1558. endp
  1559.  
  1560. ;-----------------------------------------------------------------------------
  1561. proc key.shift_f9 ;///// SET DEFAULT TAB /////////////////////////////////////
  1562. ;-----------------------------------------------------------------------------
  1563.         mov     eax,[tab_bar.Current.Ptr]
  1564.         cmp     eax,[tab_bar.Default.Ptr]
  1565.         jne     @f
  1566.         xor     eax,eax
  1567.     @@: mov     [tab_bar.Default.Ptr],eax
  1568.         mov     ebp,[tab_bar.Current.Ptr]
  1569.         call    make_tab_visible
  1570.         cmp     [tab_bar.Style],2
  1571.         jbe     @f
  1572.         call    align_editor_in_tab
  1573.         call    draw_editor
  1574.     @@: call    draw_tabctl
  1575.         ret
  1576. endp
  1577.  
  1578. ;-----------------------------------------------------------------------------
  1579. proc key.f3 ;///// FIND NEXT MATCH ///////////////////////////////////////////
  1580. ;-----------------------------------------------------------------------------
  1581.         jmp     search
  1582. endp
  1583.  
  1584. ;-----------------------------------------------------------------------------
  1585. proc key.ctrl_f9 ;///// COMPILE //////////////////////////////////////////////
  1586. ;-----------------------------------------------------------------------------
  1587.         mov     bl,0
  1588.         jmp     start_fasm
  1589. endp
  1590.  
  1591. ;-----------------------------------------------------------------------------
  1592. proc key.f9 ;///// COMPILE AND RUN ///////////////////////////////////////////
  1593. ;-----------------------------------------------------------------------------
  1594.         mov     bl,1
  1595.         jmp     start_fasm
  1596. endp
  1597.  
  1598. ;-----------------------------------------------------------------------------
  1599. proc key.f10 ;///// COMPILE AND RUN UNDER DEBUG //////////////////////////////
  1600. ;-----------------------------------------------------------------------------
  1601.         mov     bl,2
  1602.         jmp     start_fasm
  1603. endp
  1604.  
  1605. ;-----------------------------------------------------------------------------
  1606. proc key.alt_x ;///// EXIT PROGRAM ///////////////////////////////////////////
  1607. ;-----------------------------------------------------------------------------
  1608.         mov     [main_closing],1
  1609.         mov     eax,[tab_bar.Items]
  1610.         mov     [exit_tab_item],eax
  1611.         mov     eax,[tab_bar.Items.Count]
  1612.         mov     [exit_tab_num],eax
  1613.   .direct:
  1614.         call    try_to_close_tabs
  1615.         or      eax,eax
  1616.         jz      @f
  1617.         mov     [bot_mode2],2
  1618.         jmp     key.ctrl_o.direct
  1619.  
  1620.     @@: stdcall save_settings
  1621.  
  1622.   .close:
  1623.         mov     [main_closed],1
  1624.         mcall   -1
  1625. endp
  1626.  
  1627. ;-----------------------------------------------------------------------------
  1628. proc try_to_close_tabs ;///// FIND TABS TO BE SAVED BEFORE CLOSE /////////////
  1629. ;-----------------------------------------------------------------------------
  1630.         push    ecx ebp
  1631.         call    flush_cur_tab
  1632.         mov     ebp,[exit_tab_item] ; [tab_bar.Items]
  1633.         add     ebp,-sizeof.TABITEM
  1634.     @@: dec     [exit_tab_num]
  1635.         js      .ok
  1636.         add     ebp,sizeof.TABITEM
  1637.         mov     al,[ebp+TABITEM.Editor.Modified]
  1638.         cmp     [ebp+TABITEM.Editor.Modified],0
  1639.         je      @b
  1640.         mov     [exit_tab_item],ebp
  1641.         call    set_cur_tab
  1642.         call    make_tab_visible
  1643.         xor     eax,eax
  1644.         inc     eax
  1645.     @@: pop     ebp ecx
  1646.         ret
  1647.   .ok:  xor     eax,eax
  1648.         jmp     @b
  1649. endp
  1650.