Class: Kward::PromptInterface::EditorState
- Inherits:
-
Object
- Object
- Kward::PromptInterface::EditorState
- Defined in:
- lib/kward/prompt_interface/editor/state.rb
Overview
Mutable state for the built-in composer file editor.
Instance Attribute Summary collapse
-
#buffer ⇒ Object
Returns the value of attribute buffer.
-
#diff_view ⇒ Object
Returns the value of attribute diff_view.
-
#display_path ⇒ Object
readonly
Returns the value of attribute display_path.
-
#editor_mode ⇒ Object
Returns the value of attribute editor_mode.
-
#emacs_pending ⇒ Object
Returns the value of attribute emacs_pending.
-
#kill_buffer ⇒ Object
Returns the value of attribute kill_buffer.
-
#kill_ring ⇒ Object
Returns the value of attribute kill_ring.
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#last_yank_index ⇒ Object
Returns the value of attribute last_yank_index.
-
#last_yank_range ⇒ Object
Returns the value of attribute last_yank_range.
-
#new_file ⇒ Object
Returns the value of attribute new_file.
-
#original_content ⇒ Object
readonly
Returns the value of attribute original_content.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#quit_confirmed ⇒ Object
Returns the value of attribute quit_confirmed.
-
#readonly ⇒ Object
Returns the value of attribute readonly.
-
#redo_stack ⇒ Object
Returns the value of attribute redo_stack.
-
#search_active ⇒ Object
Returns the value of attribute search_active.
-
#search_direction ⇒ Object
Returns the value of attribute search_direction.
-
#search_match_ranges ⇒ Object
readonly
Returns the value of attribute search_match_ranges.
-
#search_query ⇒ Object
Returns the value of attribute search_query.
-
#status ⇒ Object
Returns the value of attribute status.
-
#undo_stack ⇒ Object
Returns the value of attribute undo_stack.
-
#vibe_state ⇒ Object
readonly
Returns the value of attribute vibe_state.
-
#viewport_column ⇒ Object
Returns the value of attribute viewport_column.
-
#viewport_row ⇒ Object
Returns the value of attribute viewport_row.
Instance Method Summary collapse
- #add_next_occurrence_selection ⇒ Object
- #add_selection(anchor, cursor = anchor) ⇒ Object
- #add_vertical_cursor(direction) ⇒ Object
- #append_search(text) ⇒ Object
- #begin_search(direction = :forward) ⇒ Object
- #begin_selection ⇒ Object
- #bind_path(path) ⇒ Object
- #cancel_search(restore_cursor: true) ⇒ Object
- #clear_search_highlights ⇒ Object
- #clear_selection ⇒ Object
- #collapse_to_primary_selection ⇒ Object
- #confirm_search ⇒ Object
- #copy_for_kill_ring(start_index, end_index) ⇒ Object
- #copy_range(start_index, end_index) ⇒ Object
- #current_line_range ⇒ Object
- #cursor ⇒ Object
- #cursor=(value) ⇒ Object
- #cursor_line_and_column ⇒ Object
- #cursor_line_and_column_for(offset) ⇒ Object
- #cut_range(start_index, end_index) ⇒ Object
- #delete_at_cursor ⇒ Object
- #delete_at_selections ⇒ Object
- #delete_before_cursor ⇒ Object
- #delete_before_selections ⇒ Object
- #delete_search_character ⇒ Object
- #delete_word_after_cursor ⇒ Object
- #delete_word_before_cursor ⇒ Object
- #diff_view? ⇒ Boolean
- #dirty? ⇒ Boolean
- #emacs? ⇒ Boolean
- #extending_selections ⇒ Object
-
#initialize(path:, content:, new_file: false, editor_mode: "modern", readonly: false, diff_view: false, virtual: false, display_path: nil, language: nil, workspace_only: false) ⇒ EditorState
constructor
A new instance of EditorState.
- #initialize_copy(other) ⇒ Object
- #insert(text) ⇒ Object
- #kill_line_after_cursor ⇒ Object
- #kill_line_before_cursor ⇒ Object
- #line_range(line_index) ⇒ Object
- #line_start_offset(line_index) ⇒ Object
- #lines ⇒ Object
- #modern? ⇒ Boolean
- #move_down ⇒ Object
- #move_file_end ⇒ Object
- #move_file_start ⇒ Object
- #move_indentation_down ⇒ Object
- #move_indentation_right ⇒ Object
- #move_indentation_up ⇒ Object
- #move_left ⇒ Object
- #move_line_end ⇒ Object
- #move_line_first_non_blank ⇒ Object
- #move_line_start ⇒ Object
- #move_right ⇒ Object
- #move_to_line_first_non_blank(line_index) ⇒ Object
- #move_to_next_word ⇒ Object
- #move_to_previous_word ⇒ Object
- #move_to_word_end ⇒ Object
- #move_up ⇒ Object
- #multi_cursor? ⇒ Boolean
- #offset_for_line_and_column(line_index, column) ⇒ Object
- #page_down(rows) ⇒ Object
- #page_up(rows) ⇒ Object
- #prompt_selections(ranges = selection_ranges) ⇒ Object
- #push_kill(text) ⇒ Object
- #push_undo ⇒ Object
- #readonly? ⇒ Boolean
- #record_undo(clear_redo_on_noop: false) ⇒ Object
- #redo ⇒ Object
- #refresh_after_save(content) ⇒ Object
- #repeat_search(direction = @search_direction, query = @search_query) ⇒ Object
- #replace_buffer(content) ⇒ Object
- #replace_range(start_index, end_index, text) ⇒ Object
- #replace_selections(text) ⇒ Object
- #secondary_cursor_offsets ⇒ Object
- #selected_text ⇒ Object
- #selection_active? ⇒ Boolean
- #selection_anchor ⇒ Object
- #selection_anchor=(value) ⇒ Object
- #selection_range ⇒ Object
- #selection_ranges ⇒ Object
- #selection_to_line_start_cursors ⇒ Object
- #selections ⇒ Object
- #set_cursor_line_and_column(line_index, column) ⇒ Object
- #set_selections(values) ⇒ Object
- #side_by_side_diff_view? ⇒ Boolean
- #undo ⇒ Object
- #vibe? ⇒ Boolean
- #vibe_command ⇒ Object
- #vibe_command=(value) ⇒ Object
- #vibe_command_range ⇒ Object
- #vibe_command_range=(value) ⇒ Object
- #vibe_command_selection ⇒ Object
- #vibe_command_selection=(selection) ⇒ Object
- #vibe_jump_back_list ⇒ Object
- #vibe_jump_back_list=(value) ⇒ Object
- #vibe_jump_forward_list ⇒ Object
- #vibe_jump_forward_list=(value) ⇒ Object
- #vibe_kill_linewise ⇒ Object
- #vibe_kill_linewise=(value) ⇒ Object
- #vibe_last_change ⇒ Object
- #vibe_last_change=(value) ⇒ Object
- #vibe_last_find ⇒ Object
- #vibe_last_find=(value) ⇒ Object
- #vibe_last_macro ⇒ Object
- #vibe_last_macro=(value) ⇒ Object
- #vibe_last_visual_selection ⇒ Object
- #vibe_last_visual_selection=(value) ⇒ Object
- #vibe_macros ⇒ Object
- #vibe_macros=(value) ⇒ Object
- #vibe_marks ⇒ Object
- #vibe_marks=(value) ⇒ Object
- #vibe_mode ⇒ Object
- #vibe_mode=(value) ⇒ Object
- #vibe_pending ⇒ Object
- #vibe_pending=(value) ⇒ Object
- #vibe_previous_change_cursor ⇒ Object
- #vibe_previous_change_cursor=(value) ⇒ Object
- #vibe_recording_macro ⇒ Object
- #vibe_recording_macro=(value) ⇒ Object
- #vibe_register_types ⇒ Object
- #vibe_register_types=(value) ⇒ Object
- #vibe_registers ⇒ Object
- #vibe_registers=(value) ⇒ Object
- #virtual? ⇒ Boolean
- #visual_block_selection_ranges ⇒ Object
- #visual_character_selection_range ⇒ Object
- #visual_line_selection_range ⇒ Object
- #word_range_at(offset) ⇒ Object
- #word_under_cursor ⇒ Object
- #workspace_only? ⇒ Boolean
- #yank_from_kill_ring ⇒ Object
- #yank_kill_buffer ⇒ Object
- #yank_pop ⇒ Object
Constructor Details
#initialize(path:, content:, new_file: false, editor_mode: "modern", readonly: false, diff_view: false, virtual: false, display_path: nil, language: nil, workspace_only: false) ⇒ EditorState
Returns a new instance of EditorState.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 24 def initialize(path:, content:, new_file: false, editor_mode: "modern", readonly: false, diff_view: false, virtual: false, display_path: nil, language: nil, workspace_only: false) @workspace_only = workspace_only virtual ||= workspace_only @path = virtual ? nil : path.to_s @display_path = display_path.to_s.empty? ? path.to_s : display_path.to_s @language = language&.to_sym @new_file = new_file @readonly = readonly || workspace_only @diff_view = diff_view @virtual = virtual == true @original_content = content.to_s @text_buffer = EditorBuffer.new(@original_content) @buffer = @text_buffer.text @cursor = 0 @viewport_row = 0 @viewport_column = 0 @status = nil @quit_confirmed = false @search = EditorSearch.new @search_active = @search.active? @search_query = @search.query @search_direction = @search.direction @search_match_ranges = [] @kill_state = EditorKillRing.new @kill_buffer = @kill_state.kill_buffer @selections = EditorSelections.new(cursor: @cursor, buffer_length: @buffer.length) sync_selection_state @editor_mode = normalize_editor_mode(editor_mode) @emacs_pending = nil @kill_ring = @kill_state.kill_ring @last_yank_range = @kill_state.last_yank_range @last_yank_index = @kill_state.last_yank_index @vibe_state = VibeEditorState.new(editor_mode: @editor_mode) sync_vibe_state @undo_history = EditorUndoHistory.new @undo_stack = @undo_history.undo_stack @redo_stack = @undo_history.redo_stack @status = default_status end |
Instance Attribute Details
#buffer ⇒ Object
Returns the value of attribute buffer.
20 21 22 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 20 def buffer @buffer end |
#diff_view ⇒ Object
Returns the value of attribute diff_view.
21 22 23 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 21 def diff_view @diff_view end |
#display_path ⇒ Object (readonly)
Returns the value of attribute display_path.
19 20 21 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 19 def display_path @display_path end |
#editor_mode ⇒ Object
Returns the value of attribute editor_mode.
21 22 23 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 21 def editor_mode @editor_mode end |
#emacs_pending ⇒ Object
Returns the value of attribute emacs_pending.
21 22 23 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 21 def emacs_pending @emacs_pending end |
#kill_buffer ⇒ Object
Returns the value of attribute kill_buffer.
20 21 22 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 20 def kill_buffer @kill_buffer end |
#kill_ring ⇒ Object
Returns the value of attribute kill_ring.
20 21 22 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 20 def kill_ring @kill_ring end |
#language ⇒ Object (readonly)
Returns the value of attribute language.
19 20 21 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 19 def language @language end |
#last_yank_index ⇒ Object
Returns the value of attribute last_yank_index.
20 21 22 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 20 def last_yank_index @last_yank_index end |
#last_yank_range ⇒ Object
Returns the value of attribute last_yank_range.
20 21 22 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 20 def last_yank_range @last_yank_range end |
#new_file ⇒ Object
Returns the value of attribute new_file.
21 22 23 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 21 def new_file @new_file end |
#original_content ⇒ Object (readonly)
Returns the value of attribute original_content.
19 20 21 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 19 def original_content @original_content end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
19 20 21 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 19 def path @path end |
#quit_confirmed ⇒ Object
Returns the value of attribute quit_confirmed.
21 22 23 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 21 def quit_confirmed @quit_confirmed end |
#readonly ⇒ Object
Returns the value of attribute readonly.
21 22 23 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 21 def readonly @readonly end |
#redo_stack ⇒ Object
Returns the value of attribute redo_stack.
20 21 22 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 20 def redo_stack @redo_stack end |
#search_active ⇒ Object
Returns the value of attribute search_active.
21 22 23 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 21 def search_active @search_active end |
#search_direction ⇒ Object
Returns the value of attribute search_direction.
21 22 23 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 21 def search_direction @search_direction end |
#search_match_ranges ⇒ Object (readonly)
Returns the value of attribute search_match_ranges.
22 23 24 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 22 def search_match_ranges @search_match_ranges end |
#search_query ⇒ Object
Returns the value of attribute search_query.
21 22 23 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 21 def search_query @search_query end |
#status ⇒ Object
Returns the value of attribute status.
21 22 23 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 21 def status @status end |
#undo_stack ⇒ Object
Returns the value of attribute undo_stack.
20 21 22 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 20 def undo_stack @undo_stack end |
#vibe_state ⇒ Object (readonly)
Returns the value of attribute vibe_state.
112 113 114 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 112 def vibe_state @vibe_state end |
#viewport_column ⇒ Object
Returns the value of attribute viewport_column.
21 22 23 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 21 def @viewport_column end |
#viewport_row ⇒ Object
Returns the value of attribute viewport_row.
21 22 23 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 21 def @viewport_row end |
Instance Method Details
#add_next_occurrence_selection ⇒ Object
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 932 def add_next_occurrence_selection range = selection_range || word_range_at(@cursor) unless range @status = "No word under cursor" return false end query = @buffer[range[0]...range[1]].to_s if query.empty? @status = "No word under cursor" return false end existing_ranges = selection_ranges existing_ranges = [range] if existing_ranges.empty? start_after = existing_ranges.map(&:last).max || range[1] if selection_range.nil? set_selections([{ anchor: range[0], cursor: range[1] }]) @status = "Selected: #{query}" return true end match = next_occurrence_range(query, start_after, existing_ranges) unless match @status = "No more matches: #{query}" return false end add_selection(match[0], match[1]) @status = "Added cursor for: #{query}" true end |
#add_selection(anchor, cursor = anchor) ⇒ Object
351 352 353 354 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 351 def add_selection(anchor, cursor = anchor) @selections.add(anchor, cursor) sync_selection_state end |
#add_vertical_cursor(direction) ⇒ Object
965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 965 def add_vertical_cursor(direction) source = direction == :up ? selections.min_by { |selection| selection[:cursor] } : selections.max_by { |selection| selection[:cursor] } line, column = cursor_line_and_column_for(source[:cursor]) target_line = direction == :up ? line - 1 : line + 1 if target_line.negative? || target_line >= lines.length @status = direction == :up ? "No line above" : "No line below" return false end target_column = [column, lines[target_line].to_s.length].min offset = line_start_offset(target_line) + target_column add_selection(offset, offset) @status = direction == :up ? "Added cursor above" : "Added cursor below" true end |
#append_search(text) ⇒ Object
1024 1025 1026 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 1024 def append_search(text) apply_search_result(@search.append(text, buffer: @buffer, cursor: @cursor)) end |
#begin_search(direction = :forward) ⇒ Object
1007 1008 1009 1010 1011 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 1007 def begin_search(direction = :forward) @status = @search.begin(direction, cursor: @cursor) sync_search_state true end |
#begin_selection ⇒ Object
741 742 743 744 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 741 def begin_selection self.selection_anchor = @cursor @status = "Selection started" end |
#bind_path(path) ⇒ Object
378 379 380 381 382 383 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 378 def bind_path(path) @path = path.to_s @display_path = @path @virtual = false @new_file = !File.exist?(@path) end |
#cancel_search(restore_cursor: true) ⇒ Object
1013 1014 1015 1016 1017 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 1013 def cancel_search(restore_cursor: true) apply_search_result(@search.cancel(restore_cursor: restore_cursor)) @search_match_ranges = [] true end |
#clear_search_highlights ⇒ Object
1019 1020 1021 1022 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 1019 def clear_search_highlights @search_match_ranges = [] true end |
#clear_selection ⇒ Object
746 747 748 749 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 746 def clear_selection @selections.clear sync_selection_state end |
#collapse_to_primary_selection ⇒ Object
356 357 358 359 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 356 def collapse_to_primary_selection @selections.collapse_to_primary sync_selection_state end |
#confirm_search ⇒ Object
1032 1033 1034 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 1032 def confirm_search apply_search_result(@search.confirm(buffer: @buffer, cursor: @cursor)) end |
#copy_for_kill_ring(start_index, end_index) ⇒ Object
923 924 925 926 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 923 def copy_for_kill_ring(start_index, end_index) start_index, end_index = [start_index, end_index].minmax push_kill(@buffer[start_index...end_index].to_s) end |
#copy_range(start_index, end_index) ⇒ Object
918 919 920 921 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 918 def copy_range(start_index, end_index) start_index, end_index = [start_index, end_index].minmax self.kill_buffer = @buffer[start_index...end_index].to_s end |
#current_line_range ⇒ Object
858 859 860 861 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 858 def current_line_range line, = cursor_line_and_column line_range(line) end |
#cursor ⇒ Object
316 317 318 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 316 def cursor @cursor end |
#cursor=(value) ⇒ Object
320 321 322 323 324 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 320 def cursor=(value) @cursor = clamp_offset(value) @selections.cursor = @cursor sync_selection_state end |
#cursor_line_and_column ⇒ Object
413 414 415 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 413 def cursor_line_and_column cursor_line_and_column_for(@cursor) end |
#cursor_line_and_column_for(offset) ⇒ Object
833 834 835 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 833 def cursor_line_and_column_for(offset) @text_buffer.line_and_column_for(offset) end |
#cut_range(start_index, end_index) ⇒ Object
928 929 930 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 928 def cut_range(start_index, end_index) kill_range(start_index, end_index) end |
#delete_at_cursor ⇒ Object
493 494 495 496 497 498 499 500 501 502 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 493 def delete_at_cursor return delete_at_selections if multi_cursor? return false unless @cursor < @buffer.length replace_editor_text(@cursor, @cursor + 1, "") @buffer = @text_buffer.text sync_selection_state changed! true end |
#delete_at_selections ⇒ Object
906 907 908 909 910 911 912 913 914 915 916 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 906 def delete_at_selections apply_selection_edits do |selection| range = selection_range_for(selection) if range[0] != range[1] "" elsif range[1] < @buffer.length selection[:cursor] = range[1] + 1 "" end end end |
#delete_before_cursor ⇒ Object
481 482 483 484 485 486 487 488 489 490 491 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 481 def delete_before_cursor return delete_before_selections if multi_cursor? return false if @cursor.zero? replace_editor_text(@cursor - 1, @cursor, "") @cursor -= 1 @buffer = @text_buffer.text sync_selection_state changed! true end |
#delete_before_selections ⇒ Object
894 895 896 897 898 899 900 901 902 903 904 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 894 def delete_before_selections apply_selection_edits do |selection| range = selection_range_for(selection) if range[0] != range[1] "" elsif range[0].positive? selection[:anchor] = range[0] - 1 "" end end end |
#delete_search_character ⇒ Object
1028 1029 1030 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 1028 def delete_search_character apply_search_result(@search.delete_character(buffer: @buffer, cursor: @cursor)) end |
#delete_word_after_cursor ⇒ Object
677 678 679 680 681 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 677 def delete_word_after_cursor return apply_selection_edits { |selection| selection[:cursor] = next_word_boundary(selection_range_for(selection)[1]); "" } if multi_cursor? kill_range(@cursor, next_word_boundary(@cursor)) end |
#delete_word_before_cursor ⇒ Object
671 672 673 674 675 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 671 def delete_word_before_cursor return apply_selection_edits { |selection| selection[:anchor] = previous_word_boundary(selection_range_for(selection)[0]); "" } if multi_cursor? kill_range(previous_word_boundary(@cursor), @cursor) end |
#diff_view? ⇒ Boolean
385 386 387 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 385 def diff_view? !@diff_view.nil? && @diff_view != false end |
#dirty? ⇒ Boolean
405 406 407 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 405 def dirty? @buffer != @original_content end |
#emacs? ⇒ Boolean
397 398 399 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 397 def emacs? @editor_mode == "emacs" end |
#extending_selections ⇒ Object
999 1000 1001 1002 1003 1004 1005 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 999 def extending_selections previous = @extending_selections @extending_selections = true yield ensure @extending_selections = previous end |
#initialize_copy(other) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 64 def initialize_copy(other) super @path = other.path&.dup @display_path = other.display_path.dup @language = other.language @virtual = other.virtual? @original_content = other.original_content.dup @text_buffer = EditorBuffer.new(other.buffer) @buffer = @text_buffer.text @status = other.status.dup @search = EditorSearch.new(direction: other.search_direction) @search_active = other.search_active @search_query = other.search_query.dup @search_direction = other.search_direction @search_match_ranges = other.search_match_ranges.map(&:dup) @kill_state = EditorKillRing.new( kill_buffer: other.kill_buffer.dup, kill_ring: other.kill_ring.map(&:dup), last_yank_range: other.last_yank_range&.dup, last_yank_index: other.last_yank_index ) @kill_buffer = @kill_state.kill_buffer @quit_confirmed = other.quit_confirmed @viewport_column = other. @selections = EditorSelections.new( cursor: @cursor, buffer_length: @buffer.length, anchor: other.selection_anchor, secondary: other.selections.drop(1).map(&:dup) ) sync_selection_state @editor_mode = other.editor_mode.dup @emacs_pending = other.emacs_pending&.dup @kill_ring = @kill_state.kill_ring @last_yank_range = @kill_state.last_yank_range @last_yank_index = @kill_state.last_yank_index @vibe_state = VibeEditorState.copy(other.vibe_state) sync_vibe_state @undo_history = EditorUndoHistory.new other.undo_stack.each { |entry| @undo_history.undo_stack << duplicate_editor_history_entry(entry) } other.redo_stack.each { |entry| @undo_history.redo_stack << duplicate_editor_history_entry(entry) } @undo_stack = @undo_history.undo_stack @redo_stack = @undo_history.redo_stack @undo_capture = nil @readonly = other.readonly @diff_view = other.diff_view end |
#insert(text) ⇒ Object
469 470 471 472 473 474 475 476 477 478 479 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 469 def insert(text) text = text.to_s return if text.empty? return replace_selections(text) if multi_cursor? replace_editor_text(@cursor, @cursor, text) @cursor += text.length @buffer = @text_buffer.text sync_selection_state changed! end |
#kill_line_after_cursor ⇒ Object
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 689 def kill_line_after_cursor if multi_cursor? return apply_selection_edits do |selection| range = selection_range_for(selection) selection[:cursor] = line_end_for_offset(range[1]) selection[:cursor] += 1 if range[0] == selection[:cursor] && selection[:cursor] < @buffer.length "" end end if current_line_empty? kill_range(empty_line_start, empty_line_end) else kill_range(@cursor, current_line_end) end end |
#kill_line_before_cursor ⇒ Object
683 684 685 686 687 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 683 def kill_line_before_cursor return apply_selection_edits { |selection| selection[:anchor] = line_start_for_offset(selection_range_for(selection)[0]); "" } if multi_cursor? kill_range(current_line_start, @cursor) end |
#line_range(line_index) ⇒ Object
841 842 843 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 841 def line_range(line_index) @text_buffer.line_range(line_index) end |
#line_start_offset(line_index) ⇒ Object
837 838 839 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 837 def line_start_offset(line_index) @text_buffer.line_start_offset(line_index) end |
#lines ⇒ Object
409 410 411 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 409 def lines @text_buffer.lines end |
#modern? ⇒ Boolean
393 394 395 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 393 def modern? @editor_mode == "modern" end |
#move_down ⇒ Object
535 536 537 538 539 540 541 542 543 544 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 535 def move_down if multi_cursor? return move_selection_cursors { |selection| move_offset_vertically(selection[:cursor], 1) } if extending_selections? return move_selections { |selection| move_offset_vertically(selection[:cursor], 1) } end line, column = cursor_line_and_column set_cursor_line_and_column(line + 1, column) end |
#move_file_end ⇒ Object
867 868 869 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 867 def move_file_end @cursor = @buffer.length end |
#move_file_start ⇒ Object
863 864 865 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 863 def move_file_start @cursor = 0 end |
#move_indentation_down ⇒ Object
643 644 645 646 647 648 649 650 651 652 653 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 643 def move_indentation_down if multi_cursor? return move_selection_cursors { |selection| indentation_offset_for(selection[:cursor], :down) } if extending_selections? return move_selections { |selection| indentation_offset_for(selection[:cursor], :down) } end line, column = cursor_line_and_column target_line = next_indentation_line(line, indentation_level_for_line(line)) move_to_indentation_line(target_line, column) end |
#move_indentation_right ⇒ Object
655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 655 def move_indentation_right if multi_cursor? return move_selection_cursors { |selection| indentation_right_offset_for(selection[:cursor]) } if extending_selections? return move_selections { |selection| indentation_right_offset_for(selection[:cursor]) } end line, column = cursor_line_and_column indentation = indentation_level_for_line(line) if column < indentation set_cursor_line_and_column(line, indentation) else move_to_word_end end end |
#move_indentation_up ⇒ Object
631 632 633 634 635 636 637 638 639 640 641 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 631 def move_indentation_up if multi_cursor? return move_selection_cursors { |selection| indentation_offset_for(selection[:cursor], :up) } if extending_selections? return move_selections { |selection| indentation_offset_for(selection[:cursor], :up) } end line, column = cursor_line_and_column target_line = previous_indentation_line(line, indentation_level_for_line(line)) move_to_indentation_line(target_line, column) end |
#move_left ⇒ Object
504 505 506 507 508 509 510 511 512 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 504 def move_left if multi_cursor? return move_selection_cursors { |selection| horizontal_grapheme_offset(selection[:cursor], -1) } if extending_selections? return move_selections { |selection| collapse_or_move_left(selection) } end @cursor = horizontal_grapheme_offset(@cursor, -1) if @cursor.positive? end |
#move_line_end ⇒ Object
568 569 570 571 572 573 574 575 576 577 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 568 def move_line_end if multi_cursor? return move_selection_cursors { |selection| line_end_for_offset(selection[:cursor]) } if extending_selections? return move_selections { |selection| line_end_for_offset(selection[:cursor]) } end line, = cursor_line_and_column set_cursor_line_and_column(line, lines[line].length) end |
#move_line_first_non_blank ⇒ Object
557 558 559 560 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 557 def move_line_first_non_blank line, = cursor_line_and_column move_to_line_first_non_blank(line) end |
#move_line_start ⇒ Object
546 547 548 549 550 551 552 553 554 555 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 546 def move_line_start if multi_cursor? return move_selection_cursors { |selection| line_start_for_offset(selection[:cursor]) } if extending_selections? return move_selections { |selection| line_start_for_offset(selection[:cursor]) } end line, = cursor_line_and_column set_cursor_line_and_column(line, 0) end |
#move_right ⇒ Object
514 515 516 517 518 519 520 521 522 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 514 def move_right if multi_cursor? return move_selection_cursors { |selection| horizontal_grapheme_offset(selection[:cursor], 1) } if extending_selections? return move_selections { |selection| collapse_or_move_right(selection) } end @cursor = horizontal_grapheme_offset(@cursor, 1) if @cursor < @buffer.length end |
#move_to_line_first_non_blank(line_index) ⇒ Object
562 563 564 565 566 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 562 def move_to_line_first_non_blank(line_index) line = [[line_index.to_i, 0].max, lines.length - 1].min column = lines[line].to_s.index(/\S/) || 0 set_cursor_line_and_column(line, column) end |
#move_to_next_word ⇒ Object
611 612 613 614 615 616 617 618 619 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 611 def move_to_next_word if multi_cursor? return move_selection_cursors { |selection| next_word_boundary(selection[:cursor]) } if extending_selections? return move_selections { |selection| next_word_boundary(selection[:cursor]) } end @cursor = next_word_boundary(@cursor) end |
#move_to_previous_word ⇒ Object
601 602 603 604 605 606 607 608 609 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 601 def move_to_previous_word if multi_cursor? return move_selection_cursors { |selection| previous_word_boundary(selection[:cursor]) } if extending_selections? return move_selections { |selection| previous_word_boundary(selection[:cursor]) } end @cursor = previous_word_boundary(@cursor) end |
#move_to_word_end ⇒ Object
621 622 623 624 625 626 627 628 629 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 621 def move_to_word_end if multi_cursor? return move_selection_cursors { |selection| next_word_end(selection[:cursor]) } if extending_selections? return move_selections { |selection| next_word_end(selection[:cursor]) } end @cursor = next_word_end(@cursor) end |
#move_up ⇒ Object
524 525 526 527 528 529 530 531 532 533 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 524 def move_up if multi_cursor? return move_selection_cursors { |selection| move_offset_vertically(selection[:cursor], -1) } if extending_selections? return move_selections { |selection| move_offset_vertically(selection[:cursor], -1) } end line, column = cursor_line_and_column set_cursor_line_and_column(line - 1, column) end |
#multi_cursor? ⇒ Boolean
340 341 342 343 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 340 def multi_cursor? sync_selection_state @selections.multi_cursor? end |
#offset_for_line_and_column(line_index, column) ⇒ Object
421 422 423 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 421 def offset_for_line_and_column(line_index, column) @text_buffer.offset_for_line_and_column(line_index, column) end |
#page_down(rows) ⇒ Object
590 591 592 593 594 595 596 597 598 599 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 590 def page_down(rows) if multi_cursor? return move_selection_cursors { |selection| move_offset_vertically(selection[:cursor], rows.to_i) } if extending_selections? return move_selections { |selection| move_offset_vertically(selection[:cursor], rows.to_i) } end line, column = cursor_line_and_column set_cursor_line_and_column(line + rows.to_i, column) end |
#page_up(rows) ⇒ Object
579 580 581 582 583 584 585 586 587 588 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 579 def page_up(rows) if multi_cursor? return move_selection_cursors { |selection| move_offset_vertically(selection[:cursor], -rows.to_i) } if extending_selections? return move_selections { |selection| move_offset_vertically(selection[:cursor], -rows.to_i) } end line, column = cursor_line_and_column set_cursor_line_and_column(line - rows.to_i, column) end |
#prompt_selections(ranges = selection_ranges) ⇒ Object
808 809 810 811 812 813 814 815 816 817 818 819 820 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 808 def prompt_selections(ranges = selection_ranges) ranges.map do |first, limit| start_line, start_column = cursor_line_and_column_for(first) # The range end is exclusive; a newline belongs to the line it ends. end_line, end_column = cursor_line_and_column_for([first, limit - 1].max) { start_line: start_line + 1, start_column: start_column + 1, end_line: end_line + 1, end_column: end_column + 1, start_offset: first, end_offset: limit, text: @buffer[first...limit].to_s } end end |
#push_kill(text) ⇒ Object
710 711 712 713 714 715 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 710 def push_kill(text) return false unless @kill_state.push(text) sync_kill_state true end |
#push_undo ⇒ Object
425 426 427 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 425 def push_undo @undo_history.push(buffer: @buffer.dup, selections: selections) end |
#readonly? ⇒ Boolean
370 371 372 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 370 def readonly? @readonly == true end |
#record_undo(clear_redo_on_noop: false) ⇒ Object
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 429 def record_undo(clear_redo_on_noop: false) return yield if @undo_capture before = @buffer selection = selections @undo_capture = { edits: [] } begin yield ensure edits = @undo_capture[:edits] @undo_capture = nil if @buffer != before entry = edits ? { edits: edits.reverse.freeze } : { buffer: before.dup } @undo_history.push(entry.merge(selections: selection)) elsif clear_redo_on_noop @redo_stack.clear end end end |
#redo ⇒ Object
459 460 461 462 463 464 465 466 467 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 459 def redo if @undo_history.redo { |entry| restore_editor_history_entry(entry) } @status = "Redo" true else @status = "Already at newest change" false end end |
#refresh_after_save(content) ⇒ Object
1054 1055 1056 1057 1058 1059 1060 1061 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 1054 def refresh_after_save(content) @new_file = false @virtual = false @display_path = @path.to_s @original_content = content.to_s @quit_confirmed = false @status = "Saved #{@path}" end |
#repeat_search(direction = @search_direction, query = @search_query) ⇒ Object
1036 1037 1038 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 1036 def repeat_search(direction = @search_direction, query = @search_query) apply_search_result(@search.repeat(buffer: @buffer, cursor: @cursor, direction: direction, query: query)) end |
#replace_buffer(content) ⇒ Object
871 872 873 874 875 876 877 878 879 880 881 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 871 def replace_buffer(content) content = content.to_s return false if content == @buffer record_undo do self.buffer = content @cursor = [@cursor, @buffer.length].min changed! true end end |
#replace_range(start_index, end_index, text) ⇒ Object
883 884 885 886 887 888 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 883 def replace_range(start_index, end_index, text) start_index, = replace_editor_text(start_index, end_index, text) @buffer = @text_buffer.text @cursor = [start_index, @buffer.length].min changed! end |
#replace_selections(text) ⇒ Object
890 891 892 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 890 def replace_selections(text) apply_selection_edits { |_selection| text.to_s } end |
#secondary_cursor_offsets ⇒ Object
361 362 363 364 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 361 def secondary_cursor_offsets sync_selection_state @selections.secondary_cursor_offsets end |
#selected_text ⇒ Object
822 823 824 825 826 827 828 829 830 831 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 822 def selected_text if vibe? && @vibe_mode == "visual_block" return selection_ranges.map { |range| @buffer[range[0]...range[1]].to_s }.join("\n") end ranges = selection_ranges return "" if ranges.empty? ranges.map { |range| @buffer[range[0]...range[1]].to_s }.join("\n") end |
#selection_active? ⇒ Boolean
751 752 753 754 755 756 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 751 def selection_active? return false if @selection_anchor.nil? return true if vibe? && %w[visual visual_line visual_block].include?(@vibe_mode) @selection_anchor != @cursor end |
#selection_anchor ⇒ Object
326 327 328 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 326 def selection_anchor @selection_anchor end |
#selection_anchor=(value) ⇒ Object
330 331 332 333 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 330 def selection_anchor=(value) @selections.anchor = value sync_selection_state end |
#selection_range ⇒ Object
758 759 760 761 762 763 764 765 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 758 def selection_range return visual_line_selection_range if vibe? && @vibe_mode == "visual_line" && selection_active? return visual_character_selection_range if vibe? && @vibe_mode == "visual" && selection_active? return visual_block_selection_ranges.first if vibe? && @vibe_mode == "visual_block" && selection_active? return nil unless primary_selection_active? [@selection_anchor, @cursor].minmax end |
#selection_ranges ⇒ Object
767 768 769 770 771 772 773 774 775 776 777 778 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 767 def selection_ranges if vibe? && %w[visual visual_line visual_block].include?(@vibe_mode) && selection_active? return visual_block_selection_ranges if @vibe_mode == "visual_block" return [selection_range] end selections.filter_map do |selection| range = selection_range_for(selection) range if range[0] != range[1] end end |
#selection_to_line_start_cursors ⇒ Object
981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 981 def selection_to_line_start_cursors range = selection_range unless range @status = "No selection" return false end start_line, = cursor_line_and_column_for(range[0]) end_line, end_column = cursor_line_and_column_for(range[1]) end_line -= 1 if end_column.zero? && end_line > start_line set_selections((start_line..end_line).map do |line_index| offset = line_start_offset(line_index) { anchor: offset, cursor: offset } end) @status = "Created #{selections.length} cursors" true end |
#selections ⇒ Object
335 336 337 338 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 335 def selections sync_selection_state @selections.all end |
#set_cursor_line_and_column(line_index, column) ⇒ Object
417 418 419 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 417 def set_cursor_line_and_column(line_index, column) @cursor = offset_for_line_and_column(line_index, column) end |
#set_selections(values) ⇒ Object
345 346 347 348 349 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 345 def set_selections(values) @selections.set(values) @cursor = @selections.primary[:cursor] sync_selection_state end |
#side_by_side_diff_view? ⇒ Boolean
389 390 391 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 389 def side_by_side_diff_view? @diff_view == DiffViewMode::SIDE_BY_SIDE end |
#undo ⇒ Object
449 450 451 452 453 454 455 456 457 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 449 def undo if @undo_history.undo { |entry| restore_editor_history_entry(entry) } @status = "Undo" true else @status = "Already at oldest change" false end end |
#vibe? ⇒ Boolean
401 402 403 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 401 def vibe? @editor_mode == "vibe" end |
#vibe_command ⇒ Object
173 174 175 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 173 def vibe_command @vibe_state.command end |
#vibe_command=(value) ⇒ Object
177 178 179 180 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 177 def vibe_command=(value) @vibe_state.command = value sync_vibe_state end |
#vibe_command_range ⇒ Object
182 183 184 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 182 def vibe_command_range @vibe_state.command_range end |
#vibe_command_range=(value) ⇒ Object
186 187 188 189 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 186 def vibe_command_range=(value) @vibe_state.command_range = value sync_vibe_state end |
#vibe_command_selection ⇒ Object
191 192 193 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 191 def vibe_command_selection @vibe_state.command_selection end |
#vibe_command_selection=(selection) ⇒ Object
195 196 197 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 195 def vibe_command_selection=(selection) @vibe_state.command_selection = selection end |
#vibe_jump_back_list ⇒ Object
271 272 273 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 271 def vibe_jump_back_list @vibe_state.jump_back_list end |
#vibe_jump_back_list=(value) ⇒ Object
275 276 277 278 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 275 def vibe_jump_back_list=(value) @vibe_state.jump_back_list = value sync_vibe_state end |
#vibe_jump_forward_list ⇒ Object
280 281 282 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 280 def vibe_jump_forward_list @vibe_state.jump_forward_list end |
#vibe_jump_forward_list=(value) ⇒ Object
284 285 286 287 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 284 def vibe_jump_forward_list=(value) @vibe_state.jump_forward_list = value sync_vibe_state end |
#vibe_kill_linewise ⇒ Object
253 254 255 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 253 def vibe_kill_linewise @vibe_state.kill_linewise end |
#vibe_kill_linewise=(value) ⇒ Object
257 258 259 260 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 257 def vibe_kill_linewise=(value) @vibe_state.kill_linewise = value sync_vibe_state end |
#vibe_last_change ⇒ Object
199 200 201 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 199 def vibe_last_change @vibe_state.last_change end |
#vibe_last_change=(value) ⇒ Object
203 204 205 206 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 203 def vibe_last_change=(value) @vibe_state.last_change = value sync_vibe_state end |
#vibe_last_find ⇒ Object
208 209 210 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 208 def vibe_last_find @vibe_state.last_find end |
#vibe_last_find=(value) ⇒ Object
212 213 214 215 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 212 def vibe_last_find=(value) @vibe_state.last_find = value sync_vibe_state end |
#vibe_last_macro ⇒ Object
307 308 309 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 307 def vibe_last_macro @vibe_state.last_macro end |
#vibe_last_macro=(value) ⇒ Object
311 312 313 314 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 311 def vibe_last_macro=(value) @vibe_state.last_macro = value sync_vibe_state end |
#vibe_last_visual_selection ⇒ Object
217 218 219 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 217 def vibe_last_visual_selection @vibe_state.last_visual_selection end |
#vibe_last_visual_selection=(value) ⇒ Object
221 222 223 224 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 221 def vibe_last_visual_selection=(value) @vibe_state.last_visual_selection = value sync_vibe_state end |
#vibe_macros ⇒ Object
289 290 291 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 289 def vibe_macros @vibe_state.macros end |
#vibe_macros=(value) ⇒ Object
293 294 295 296 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 293 def vibe_macros=(value) @vibe_state.macros = value sync_vibe_state end |
#vibe_marks ⇒ Object
226 227 228 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 226 def vibe_marks @vibe_state.marks end |
#vibe_marks=(value) ⇒ Object
230 231 232 233 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 230 def vibe_marks=(value) @vibe_state.marks = value sync_vibe_state end |
#vibe_mode ⇒ Object
155 156 157 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 155 def vibe_mode @vibe_state.mode end |
#vibe_mode=(value) ⇒ Object
159 160 161 162 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 159 def vibe_mode=(value) @vibe_state.mode = value sync_vibe_state end |
#vibe_pending ⇒ Object
164 165 166 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 164 def vibe_pending @vibe_state.pending end |
#vibe_pending=(value) ⇒ Object
168 169 170 171 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 168 def vibe_pending=(value) @vibe_state.pending = value sync_vibe_state end |
#vibe_previous_change_cursor ⇒ Object
262 263 264 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 262 def vibe_previous_change_cursor @vibe_state.previous_change_cursor end |
#vibe_previous_change_cursor=(value) ⇒ Object
266 267 268 269 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 266 def vibe_previous_change_cursor=(value) @vibe_state.previous_change_cursor = value sync_vibe_state end |
#vibe_recording_macro ⇒ Object
298 299 300 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 298 def vibe_recording_macro @vibe_state.recording_macro end |
#vibe_recording_macro=(value) ⇒ Object
302 303 304 305 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 302 def vibe_recording_macro=(value) @vibe_state.recording_macro = value sync_vibe_state end |
#vibe_register_types ⇒ Object
244 245 246 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 244 def vibe_register_types @vibe_state.register_types end |
#vibe_register_types=(value) ⇒ Object
248 249 250 251 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 248 def vibe_register_types=(value) @vibe_state.register_types = value sync_vibe_state end |
#vibe_registers ⇒ Object
235 236 237 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 235 def vibe_registers @vibe_state.registers end |
#vibe_registers=(value) ⇒ Object
239 240 241 242 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 239 def vibe_registers=(value) @vibe_state.registers = value sync_vibe_state end |
#virtual? ⇒ Boolean
374 375 376 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 374 def virtual? @virtual == true end |
#visual_block_selection_ranges ⇒ Object
794 795 796 797 798 799 800 801 802 803 804 805 806 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 794 def visual_block_selection_ranges anchor_line, anchor_column = cursor_line_and_column_for(@selection_anchor) cursor_line, cursor_column = cursor_line_and_column start_line, end_line = [anchor_line, cursor_line].minmax start_column, end_column = [anchor_column, cursor_column].minmax (start_line..end_line).map do |line_index| line_start = line_start_offset(line_index) line_length = lines[line_index].to_s.length range_start = line_start + [start_column, line_length].min range_end = line_start + [end_column + 1, line_length].min [range_start, range_end] end end |
#visual_character_selection_range ⇒ Object
780 781 782 783 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 780 def visual_character_selection_range start_index, end_index = [@selection_anchor, @cursor].minmax [start_index, [end_index + 1, @buffer.length].min] end |
#visual_line_selection_range ⇒ Object
785 786 787 788 789 790 791 792 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 785 def visual_line_selection_range anchor_line, = cursor_line_and_column_for(@selection_anchor) cursor_line, = cursor_line_and_column start_line, end_line = [anchor_line, cursor_line].minmax start_index, = line_range(start_line) _, end_index = line_range(end_line) [start_index, end_index] end |
#word_range_at(offset) ⇒ Object
845 846 847 848 849 850 851 852 853 854 855 856 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 845 def word_range_at(offset) return nil if @buffer.empty? index = [[offset.to_i, 0].max, @buffer.length - 1].min return nil if word_separator?(@buffer[index]) start_index = index start_index -= 1 while start_index.positive? && !word_separator?(@buffer[start_index - 1]) end_index = index + 1 end_index += 1 while end_index < @buffer.length && !word_separator?(@buffer[end_index]) [start_index, end_index] end |
#word_under_cursor ⇒ Object
1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 1040 def word_under_cursor return "" if @buffer.empty? index = [[@cursor, 0].max, @buffer.length - 1].min index -= 1 while index.positive? && word_separator?(@buffer[index]) return "" if word_separator?(@buffer[index]) start_index = index start_index -= 1 while start_index.positive? && !word_separator?(@buffer[start_index - 1]) end_index = index + 1 end_index += 1 while end_index < @buffer.length && !word_separator?(@buffer[end_index]) @buffer[start_index...end_index].to_s end |
#workspace_only? ⇒ Boolean
366 367 368 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 366 def workspace_only? @workspace_only end |
#yank_from_kill_ring ⇒ Object
717 718 719 720 721 722 723 724 725 726 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 717 def yank_from_kill_ring text = @kill_state.first_yank return false unless text start_index = @cursor insert(text) @kill_state.record_yank(start_index, @cursor) sync_kill_state true end |
#yank_kill_buffer ⇒ Object
706 707 708 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 706 def yank_kill_buffer replace_selections(@kill_buffer.to_s) unless @kill_buffer.to_s.empty? end |
#yank_pop ⇒ Object
728 729 730 731 732 733 734 735 736 737 738 739 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 728 def yank_pop yank = @kill_state.next_yank_pop return false unless yank start_index, end_index = yank[:range] text = yank[:text] replace_range(start_index, end_index, text) @cursor = start_index + text.length @kill_state.record_yank_pop(start_index, @cursor) sync_kill_state true end |