Added select_word_another function.
This commit is contained in:
parent
bb9673ff92
commit
6acf7ff669
|
@ -419,7 +419,9 @@ key esc M alt+n selection_mode_normal
|
|||
key esc M esc N selection_mode_normal
|
||||
key esc ctrl+space select_line
|
||||
key esc space select_wrapping_block
|
||||
key.after anchor_selection ctrl+space select_word
|
||||
key.after anchor_selection ctrl+space select_word
|
||||
key.after select_word ctrl+space select_word_another
|
||||
key.after select_word_another ctrl+space select_word_another
|
||||
|
||||
# Select file diff in a patch
|
||||
key ctrl+alt+d f select_block /^Index: /, /^(Index: |$)/, false
|
||||
|
|
|
@ -121,6 +121,29 @@ module Diakonos
|
|||
cursor_to( start_row, 0, DO_DISPLAY )
|
||||
end
|
||||
|
||||
def select_word
|
||||
coords = word_under_cursor_pos( or_after: true )
|
||||
if coords
|
||||
cursor_to *coords[1]
|
||||
set_selection *(coords.flatten)
|
||||
display
|
||||
end
|
||||
end
|
||||
|
||||
def select_word_another
|
||||
m = selection_mark
|
||||
if m.nil?
|
||||
select_word
|
||||
else
|
||||
row, col, _ = pos_of_next( /\w\b/, @last_row, @last_col )
|
||||
if row && col
|
||||
cursor_to row, col+1
|
||||
set_selection m.start_row, m.start_col, row, col+1
|
||||
display
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def select( from_regexp, to_regexp, include_ending = true )
|
||||
start_row = nil
|
||||
|
||||
|
|
|
@ -78,11 +78,11 @@ module Diakonos
|
|||
# Selects the word at the current cursor position.
|
||||
# If the cursor is not on a word character, the first word following the cursor is selected.
|
||||
def select_word
|
||||
coords = buffer_current.word_under_cursor_pos( or_after: true )
|
||||
if coords
|
||||
buffer_current.set_selection *(coords.flatten)
|
||||
buffer_current.display
|
||||
end
|
||||
buffer_current.select_word
|
||||
end
|
||||
|
||||
def select_word_another
|
||||
buffer_current.select_word_another
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -61,44 +61,57 @@ describe 'A Diakonos user can' do
|
|||
it 'select the word at the cursor position' do
|
||||
@b.cursor_to 2,4
|
||||
@d.select_word
|
||||
s = @b.selection_mark
|
||||
s.should.not.be.nil
|
||||
s.start_row.should.equal 2
|
||||
s.end_row.should.equal 2
|
||||
s.start_col.should.equal 2
|
||||
s.end_col.should.equal 6
|
||||
selection_should_be 2,2, 2,6
|
||||
cursor_should_be_at 2,6
|
||||
|
||||
@b.cursor_to 2,2
|
||||
@d.select_word
|
||||
s = @b.selection_mark
|
||||
s.should.not.be.nil
|
||||
s.start_row.should.equal 2
|
||||
s.end_row.should.equal 2
|
||||
s.start_col.should.equal 2
|
||||
s.end_col.should.equal 6
|
||||
selection_should_be 2,2, 2,6
|
||||
cursor_should_be_at 2,6
|
||||
|
||||
@b.cursor_to 2,5
|
||||
@d.select_word
|
||||
s = @b.selection_mark
|
||||
s.should.not.be.nil
|
||||
s.start_row.should.equal 2
|
||||
s.end_row.should.equal 2
|
||||
s.start_col.should.equal 2
|
||||
s.end_col.should.equal 6
|
||||
selection_should_be 2,2, 2,6
|
||||
cursor_should_be_at 2,6
|
||||
|
||||
@b.cursor_to 2,1
|
||||
@d.select_word
|
||||
s = @b.selection_mark
|
||||
s.should.not.be.nil
|
||||
s.start_row.should.equal 2
|
||||
s.end_row.should.equal 2
|
||||
s.start_col.should.equal 2
|
||||
s.end_col.should.equal 6
|
||||
selection_should_be 2,2, 2,6
|
||||
cursor_should_be_at 2,6
|
||||
|
||||
@b.cursor_to 26,40
|
||||
@d.select_word
|
||||
s = @b.selection_mark
|
||||
s.should.be.nil
|
||||
cursor_should_be_at 26,40
|
||||
end
|
||||
|
||||
it 'extend a selection wordwise' do
|
||||
@b.cursor_to 2,4
|
||||
@d.select_word
|
||||
selection_should_be 2,2, 2,6
|
||||
|
||||
@d.select_word_another
|
||||
selection_should_be 2,2, 2,9
|
||||
cursor_should_be_at 2,9
|
||||
@d.select_word_another
|
||||
selection_should_be 2,2, 2,14
|
||||
cursor_should_be_at 2,14
|
||||
@d.select_word_another
|
||||
selection_should_be 2,2, 2,16
|
||||
cursor_should_be_at 2,16
|
||||
@d.select_word_another
|
||||
selection_should_be 2,2, 2,23
|
||||
cursor_should_be_at 2,23
|
||||
|
||||
@b.cursor_to 26,34
|
||||
@d.select_word
|
||||
selection_should_be 26,34, 26,36
|
||||
|
||||
@d.select_word_another
|
||||
selection_should_be 26,34, 26,40
|
||||
@d.select_word_another
|
||||
selection_should_be 26,34, 26,40
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -39,6 +39,14 @@ def numbered_buffer_should_be_named( number, name_expected )
|
|||
name.should.equal name_expected
|
||||
end
|
||||
|
||||
def selection_should_be( start_row, start_col, end_row, end_col )
|
||||
s = @b.selection_mark
|
||||
s.should.not.be.nil
|
||||
s.start_row.should.equal start_row
|
||||
s.end_row.should.equal end_row
|
||||
s.start_col.should.equal start_col
|
||||
s.end_col.should.equal end_col
|
||||
end
|
||||
|
||||
if $diakonos.nil?
|
||||
$diakonos = Diakonos::Diakonos.new [ '-e', 'quit', '--test', ]
|
||||
|
|
Loading…
Reference in a new issue