Subversion Repositories Kolibri OS

Rev

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