Subversion Repositories Kolibri OS

Rev

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