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.
-
#original_digest ⇒ Object
readonly
Returns the value of attribute original_digest.
-
#original_mtime ⇒ Object
readonly
Returns the value of attribute original_mtime.
-
#original_size ⇒ Object
readonly
Returns the value of attribute original_size.
-
#overwrite_confirmed ⇒ Object
Returns the value of attribute overwrite_confirmed.
-
#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
- #file_changed_on_disk? ⇒ Boolean
-
#initialize(path:, content:, new_file: false, editor_mode: "modern", readonly: false, diff_view: false, virtual: false, display_path: nil, language: nil) ⇒ 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
- #push_kill(text) ⇒ Object
- #push_undo ⇒ Object
- #readonly? ⇒ Boolean
- #redo ⇒ Object
- #refresh_after_save(content) ⇒ Object
- #repeat_search(direction = @search_direction, query = @search_query) ⇒ 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_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
- #vibe_visual_block_insert ⇒ Object
- #vibe_visual_block_insert=(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
- #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) ⇒ 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 63 64 65 |
# 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) @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 @diff_view = diff_view @virtual = virtual == true @file_marker = EditorFileMarker.new(path: @path || @display_path, content: content, new_file: new_file || virtual?) @original_content = @file_marker.content @original_digest = @file_marker.digest @original_mtime = @file_marker.mtime @original_size = @file_marker.size @text_buffer = EditorBuffer.new(@original_content) @buffer = @text_buffer.text @cursor = 0 @viewport_row = 0 @viewport_column = 0 @status = nil @overwrite_confirmed = false @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 |
#original_digest ⇒ Object (readonly)
Returns the value of attribute original_digest.
19 20 21 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 19 def original_digest @original_digest end |
#original_mtime ⇒ Object (readonly)
Returns the value of attribute original_mtime.
19 20 21 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 19 def original_mtime @original_mtime end |
#original_size ⇒ Object (readonly)
Returns the value of attribute original_size.
19 20 21 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 19 def original_size @original_size end |
#overwrite_confirmed ⇒ Object
Returns the value of attribute overwrite_confirmed.
21 22 23 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 21 def overwrite_confirmed @overwrite_confirmed 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.
118 119 120 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 118 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
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 888 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
344 345 346 347 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 344 def add_selection(anchor, cursor = anchor) @selections.add(anchor, cursor) sync_selection_state end |
#add_vertical_cursor(direction) ⇒ Object
921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 921 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
980 981 982 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 980 def append_search(text) apply_search_result(@search.append(text, buffer: @buffer, cursor: @cursor)) end |
#begin_search(direction = :forward) ⇒ Object
963 964 965 966 967 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 963 def begin_search(direction = :forward) @status = @search.begin(direction, cursor: @cursor) sync_search_state true end |
#begin_selection ⇒ Object
717 718 719 720 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 717 def begin_selection self.selection_anchor = @cursor @status = "Selection started" end |
#bind_path(path) ⇒ Object
367 368 369 370 371 372 373 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 367 def bind_path(path) @path = path.to_s @display_path = @path @virtual = false @new_file = !File.exist?(@path) @file_marker = EditorFileMarker.new(path: @path, content: @original_content, new_file: true) end |
#cancel_search(restore_cursor: true) ⇒ Object
969 970 971 972 973 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 969 def cancel_search(restore_cursor: true) apply_search_result(@search.cancel(restore_cursor: restore_cursor)) @search_match_ranges = [] true end |
#clear_search_highlights ⇒ Object
975 976 977 978 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 975 def clear_search_highlights @search_match_ranges = [] true end |
#clear_selection ⇒ Object
722 723 724 725 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 722 def clear_selection @selections.clear sync_selection_state end |
#collapse_to_primary_selection ⇒ Object
349 350 351 352 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 349 def collapse_to_primary_selection @selections.collapse_to_primary sync_selection_state end |
#confirm_search ⇒ Object
988 989 990 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 988 def confirm_search apply_search_result(@search.confirm(buffer: @buffer, cursor: @cursor)) end |
#copy_for_kill_ring(start_index, end_index) ⇒ Object
879 880 881 882 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 879 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
874 875 876 877 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 874 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
826 827 828 829 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 826 def current_line_range line, = cursor_line_and_column line_range(line) end |
#cursor ⇒ Object
309 310 311 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 309 def cursor @cursor end |
#cursor=(value) ⇒ Object
313 314 315 316 317 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 313 def cursor=(value) @cursor = clamp_offset(value) @selections.cursor = @cursor sync_selection_state end |
#cursor_line_and_column ⇒ Object
403 404 405 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 403 def cursor_line_and_column cursor_line_and_column_for(@cursor) end |
#cursor_line_and_column_for(offset) ⇒ Object
795 796 797 798 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 795 def cursor_line_and_column_for(offset) before_cursor = @buffer[0...offset].to_s [before_cursor.count("\n"), (before_cursor.split("\n", -1).last || "").length] end |
#cut_range(start_index, end_index) ⇒ Object
884 885 886 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 884 def cut_range(start_index, end_index) kill_range(start_index, end_index) end |
#delete_at_cursor ⇒ Object
469 470 471 472 473 474 475 476 477 478 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 469 def delete_at_cursor return delete_at_selections if multi_cursor? return false unless @cursor < @buffer.length @text_buffer.delete_range(@cursor, @cursor + 1) @buffer = @text_buffer.text sync_selection_state changed! true end |
#delete_at_selections ⇒ Object
862 863 864 865 866 867 868 869 870 871 872 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 862 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
457 458 459 460 461 462 463 464 465 466 467 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 457 def delete_before_cursor return delete_before_selections if multi_cursor? return false if @cursor.zero? @text_buffer.delete_range(@cursor - 1, @cursor) @cursor -= 1 @buffer = @text_buffer.text sync_selection_state changed! true end |
#delete_before_selections ⇒ Object
850 851 852 853 854 855 856 857 858 859 860 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 850 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
984 985 986 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 984 def delete_search_character apply_search_result(@search.delete_character(buffer: @buffer, cursor: @cursor)) end |
#delete_word_after_cursor ⇒ Object
653 654 655 656 657 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 653 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
647 648 649 650 651 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 647 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
375 376 377 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 375 def diff_view? !@diff_view.nil? && @diff_view != false end |
#dirty? ⇒ Boolean
395 396 397 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 395 def dirty? @buffer != @original_content end |
#emacs? ⇒ Boolean
387 388 389 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 387 def emacs? @editor_mode == "emacs" end |
#extending_selections ⇒ Object
955 956 957 958 959 960 961 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 955 def extending_selections previous = @extending_selections @extending_selections = true yield ensure @extending_selections = previous end |
#file_changed_on_disk? ⇒ Boolean
1024 1025 1026 1027 1028 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 1024 def file_changed_on_disk? return false if virtual? @file_marker.changed_on_disk?(new_file: new_file) end |
#initialize_copy(other) ⇒ Object
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 111 112 113 114 115 116 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 67 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 @file_marker = EditorFileMarker.new(path: @path || @display_path, content: @original_content, new_file: other.new_file || @virtual) @original_digest = other.original_digest.dup @original_mtime = other.original_mtime @original_size = other.original_size @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_snapshot(entry) } other.redo_stack.each { |entry| @undo_history.redo_stack << duplicate_editor_snapshot(entry) } @undo_stack = @undo_history.undo_stack @redo_stack = @undo_history.redo_stack @readonly = other.readonly @diff_view = other.diff_view end |
#insert(text) ⇒ Object
445 446 447 448 449 450 451 452 453 454 455 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 445 def insert(text) text = text.to_s return if text.empty? return replace_selections(text) if multi_cursor? @text_buffer.insert(@cursor, text) @cursor += text.length @buffer = @text_buffer.text sync_selection_state changed! end |
#kill_line_after_cursor ⇒ Object
665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 665 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
659 660 661 662 663 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 659 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
806 807 808 809 810 811 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 806 def line_range(line_index) start_index = line_start_offset(line_index) end_index = start_index + lines[line_index].to_s.length end_index += 1 if end_index < @buffer.length [start_index, end_index] end |
#line_start_offset(line_index) ⇒ Object
800 801 802 803 804 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 800 def line_start_offset(line_index) values = lines line_index = [[line_index.to_i, 0].max, values.length - 1].min values.first(line_index).sum { |line| line.length + 1 } end |
#lines ⇒ Object
399 400 401 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 399 def lines @text_buffer.lines end |
#modern? ⇒ Boolean
383 384 385 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 383 def modern? @editor_mode == "modern" end |
#move_down ⇒ Object
511 512 513 514 515 516 517 518 519 520 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 511 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
835 836 837 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 835 def move_file_end @cursor = @buffer.length end |
#move_file_start ⇒ Object
831 832 833 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 831 def move_file_start @cursor = 0 end |
#move_indentation_down ⇒ Object
619 620 621 622 623 624 625 626 627 628 629 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 619 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
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 631 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
607 608 609 610 611 612 613 614 615 616 617 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 607 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
480 481 482 483 484 485 486 487 488 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 480 def move_left if multi_cursor? return move_selection_cursors { |selection| [selection[:cursor] - 1, 0].max } if extending_selections? return move_selections { |selection| collapse_or_move_left(selection) } end @cursor -= 1 if @cursor.positive? end |
#move_line_end ⇒ Object
544 545 546 547 548 549 550 551 552 553 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 544 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
533 534 535 536 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 533 def move_line_first_non_blank line, = cursor_line_and_column move_to_line_first_non_blank(line) end |
#move_line_start ⇒ Object
522 523 524 525 526 527 528 529 530 531 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 522 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
490 491 492 493 494 495 496 497 498 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 490 def move_right if multi_cursor? return move_selection_cursors { |selection| [selection[:cursor] + 1, @buffer.length].min } if extending_selections? return move_selections { |selection| collapse_or_move_right(selection) } end @cursor += 1 if @cursor < @buffer.length end |
#move_to_line_first_non_blank(line_index) ⇒ Object
538 539 540 541 542 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 538 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
587 588 589 590 591 592 593 594 595 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 587 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
577 578 579 580 581 582 583 584 585 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 577 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
597 598 599 600 601 602 603 604 605 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 597 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
500 501 502 503 504 505 506 507 508 509 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 500 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
333 334 335 336 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 333 def multi_cursor? sync_selection_state @selections.multi_cursor? end |
#offset_for_line_and_column(line_index, column) ⇒ Object
411 412 413 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 411 def offset_for_line_and_column(line_index, column) @text_buffer.offset_for_line_and_column(line_index, column) end |
#page_down(rows) ⇒ Object
566 567 568 569 570 571 572 573 574 575 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 566 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
555 556 557 558 559 560 561 562 563 564 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 555 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 |
#push_kill(text) ⇒ Object
686 687 688 689 690 691 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 686 def push_kill(text) return false unless @kill_state.push(text) sync_kill_state true end |
#push_undo ⇒ Object
415 416 417 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 415 def push_undo @undo_history.push(editor_snapshot) end |
#readonly? ⇒ Boolean
359 360 361 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 359 def readonly? @readonly == true end |
#redo ⇒ Object
432 433 434 435 436 437 438 439 440 441 442 443 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 432 def redo snapshot = @undo_history.redo(editor_snapshot) unless snapshot @status = "Already at newest change" return false end restore_editor_snapshot(snapshot) changed! @status = "Redo" true end |
#refresh_after_save(content) ⇒ Object
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 1010 def refresh_after_save(content) @new_file = false @virtual = false @display_path = @path.to_s @file_marker.refresh(content) @original_content = @file_marker.content @original_digest = @file_marker.digest @original_mtime = @file_marker.mtime @original_size = @file_marker.size @overwrite_confirmed = false @quit_confirmed = false @status = "Saved #{@path}" end |
#repeat_search(direction = @search_direction, query = @search_query) ⇒ Object
992 993 994 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 992 def repeat_search(direction = @search_direction, query = @search_query) apply_search_result(@search.repeat(buffer: @buffer, cursor: @cursor, direction: direction, query: query)) end |
#replace_range(start_index, end_index, text) ⇒ Object
839 840 841 842 843 844 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 839 def replace_range(start_index, end_index, text) start_index, = @text_buffer.replace_range(start_index, end_index, text) @buffer = @text_buffer.text @cursor = [start_index, @buffer.length].min changed! end |
#replace_selections(text) ⇒ Object
846 847 848 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 846 def replace_selections(text) apply_selection_edits { |_selection| text.to_s } end |
#secondary_cursor_offsets ⇒ Object
354 355 356 357 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 354 def secondary_cursor_offsets sync_selection_state @selections.secondary_cursor_offsets end |
#selected_text ⇒ Object
784 785 786 787 788 789 790 791 792 793 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 784 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
727 728 729 730 731 732 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 727 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
319 320 321 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 319 def selection_anchor @selection_anchor end |
#selection_anchor=(value) ⇒ Object
323 324 325 326 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 323 def selection_anchor=(value) @selections.anchor = value sync_selection_state end |
#selection_range ⇒ Object
734 735 736 737 738 739 740 741 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 734 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
743 744 745 746 747 748 749 750 751 752 753 754 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 743 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
937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 937 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
328 329 330 331 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 328 def selections sync_selection_state @selections.all end |
#set_cursor_line_and_column(line_index, column) ⇒ Object
407 408 409 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 407 def set_cursor_line_and_column(line_index, column) @cursor = offset_for_line_and_column(line_index, column) end |
#set_selections(values) ⇒ Object
338 339 340 341 342 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 338 def set_selections(values) @selections.set(values) @cursor = @selections.primary[:cursor] sync_selection_state end |
#side_by_side_diff_view? ⇒ Boolean
379 380 381 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 379 def side_by_side_diff_view? @diff_view == DiffViewMode::SIDE_BY_SIDE end |
#undo ⇒ Object
419 420 421 422 423 424 425 426 427 428 429 430 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 419 def undo snapshot = @undo_history.undo(editor_snapshot) unless snapshot @status = "Already at oldest change" return false end restore_editor_snapshot(snapshot) changed! @status = "Undo" true end |
#vibe? ⇒ Boolean
391 392 393 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 391 def vibe? @editor_mode == "vibe" end |
#vibe_command ⇒ Object
174 175 176 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 174 def vibe_command @vibe_state.command end |
#vibe_command=(value) ⇒ Object
178 179 180 181 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 178 def vibe_command=(value) @vibe_state.command = value sync_vibe_state end |
#vibe_jump_back_list ⇒ Object
264 265 266 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 264 def vibe_jump_back_list @vibe_state.jump_back_list end |
#vibe_jump_back_list=(value) ⇒ Object
268 269 270 271 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 268 def vibe_jump_back_list=(value) @vibe_state.jump_back_list = value sync_vibe_state end |
#vibe_jump_forward_list ⇒ Object
273 274 275 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 273 def vibe_jump_forward_list @vibe_state.jump_forward_list end |
#vibe_jump_forward_list=(value) ⇒ Object
277 278 279 280 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 277 def vibe_jump_forward_list=(value) @vibe_state.jump_forward_list = value sync_vibe_state end |
#vibe_kill_linewise ⇒ Object
246 247 248 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 246 def vibe_kill_linewise @vibe_state.kill_linewise end |
#vibe_kill_linewise=(value) ⇒ Object
250 251 252 253 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 250 def vibe_kill_linewise=(value) @vibe_state.kill_linewise = value sync_vibe_state end |
#vibe_last_change ⇒ Object
183 184 185 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 183 def vibe_last_change @vibe_state.last_change end |
#vibe_last_change=(value) ⇒ Object
187 188 189 190 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 187 def vibe_last_change=(value) @vibe_state.last_change = value sync_vibe_state end |
#vibe_last_find ⇒ Object
192 193 194 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 192 def vibe_last_find @vibe_state.last_find end |
#vibe_last_find=(value) ⇒ Object
196 197 198 199 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 196 def vibe_last_find=(value) @vibe_state.last_find = value sync_vibe_state end |
#vibe_last_macro ⇒ Object
300 301 302 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 300 def vibe_last_macro @vibe_state.last_macro end |
#vibe_last_macro=(value) ⇒ Object
304 305 306 307 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 304 def vibe_last_macro=(value) @vibe_state.last_macro = value sync_vibe_state end |
#vibe_last_visual_selection ⇒ Object
201 202 203 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 201 def vibe_last_visual_selection @vibe_state.last_visual_selection end |
#vibe_last_visual_selection=(value) ⇒ Object
205 206 207 208 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 205 def vibe_last_visual_selection=(value) @vibe_state.last_visual_selection = value sync_vibe_state end |
#vibe_macros ⇒ Object
282 283 284 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 282 def vibe_macros @vibe_state.macros end |
#vibe_macros=(value) ⇒ Object
286 287 288 289 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 286 def vibe_macros=(value) @vibe_state.macros = value sync_vibe_state end |
#vibe_marks ⇒ Object
219 220 221 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 219 def vibe_marks @vibe_state.marks end |
#vibe_marks=(value) ⇒ Object
223 224 225 226 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 223 def vibe_marks=(value) @vibe_state.marks = value sync_vibe_state end |
#vibe_mode ⇒ Object
156 157 158 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 156 def vibe_mode @vibe_state.mode end |
#vibe_mode=(value) ⇒ Object
160 161 162 163 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 160 def vibe_mode=(value) @vibe_state.mode = value sync_vibe_state end |
#vibe_pending ⇒ Object
165 166 167 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 165 def vibe_pending @vibe_state.pending end |
#vibe_pending=(value) ⇒ Object
169 170 171 172 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 169 def vibe_pending=(value) @vibe_state.pending = value sync_vibe_state end |
#vibe_previous_change_cursor ⇒ Object
255 256 257 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 255 def vibe_previous_change_cursor @vibe_state.previous_change_cursor end |
#vibe_previous_change_cursor=(value) ⇒ Object
259 260 261 262 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 259 def vibe_previous_change_cursor=(value) @vibe_state.previous_change_cursor = value sync_vibe_state end |
#vibe_recording_macro ⇒ Object
291 292 293 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 291 def vibe_recording_macro @vibe_state.recording_macro end |
#vibe_recording_macro=(value) ⇒ Object
295 296 297 298 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 295 def vibe_recording_macro=(value) @vibe_state.recording_macro = value sync_vibe_state end |
#vibe_register_types ⇒ Object
237 238 239 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 237 def vibe_register_types @vibe_state.register_types end |
#vibe_register_types=(value) ⇒ Object
241 242 243 244 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 241 def vibe_register_types=(value) @vibe_state.register_types = value sync_vibe_state end |
#vibe_registers ⇒ Object
228 229 230 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 228 def vibe_registers @vibe_state.registers end |
#vibe_registers=(value) ⇒ Object
232 233 234 235 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 232 def vibe_registers=(value) @vibe_state.registers = value sync_vibe_state end |
#vibe_visual_block_insert ⇒ Object
210 211 212 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 210 def vibe_visual_block_insert @vibe_state.visual_block_insert end |
#vibe_visual_block_insert=(value) ⇒ Object
214 215 216 217 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 214 def vibe_visual_block_insert=(value) @vibe_state.visual_block_insert = value sync_vibe_state end |
#virtual? ⇒ Boolean
363 364 365 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 363 def virtual? @virtual == true end |
#visual_block_selection_ranges ⇒ Object
770 771 772 773 774 775 776 777 778 779 780 781 782 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 770 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
756 757 758 759 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 756 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
761 762 763 764 765 766 767 768 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 761 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
813 814 815 816 817 818 819 820 821 822 823 824 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 813 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
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 996 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 |
#yank_from_kill_ring ⇒ Object
693 694 695 696 697 698 699 700 701 702 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 693 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
682 683 684 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 682 def yank_kill_buffer replace_selections(@kill_buffer.to_s) unless @kill_buffer.to_s.empty? end |
#yank_pop ⇒ Object
704 705 706 707 708 709 710 711 712 713 714 715 |
# File 'lib/kward/prompt_interface/editor/state.rb', line 704 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 |