Subversion Repositories Kolibri OS

Rev

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

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