Re: [code] Adding multiple selection on double click

From: Mitchell <m.att.foicica.com>
Date: Thu, 13 Jul 2017 18:14:04 -0400 (EDT)

Hi Milind,

On Thu, 13 Jul 2017, Milind Gupta wrote:

> Hi,
> I am trying to add a functionality similar to notepad++ where when a
> word is double clicked all similar words are highlighted in the document.
> It works fine except it scrolls down to the bottom of the document and does
> not maintain the scroll position. Here is my code:
>
> events.connect(events.DOUBLE_CLICK,function(string)
> local fl = buffer.first_visible_line
> local cp = buffer.current_pos
> local pos = findAllAtCursor()
> for i = 1,#pos do
> buffer:add_selection(pos[i][2],pos[i][1])
> end
> buffer:scroll_range(cp,buffer:position_from_line(fl))
> end
> )
>
> findAllAtCursor is from the findall.lua file here
> https://foicica.com/wiki/multi-edit.
>
> The scroll_range command works fine if I run it from the command entry but
> somehow here it does not reset the scroll view. Also is there a way to
> prevent the scrolling from happening in the first place. I think
> add_selection scroll it.

Try replacing your `buffer:scroll_range()` call with `buffer.first_visible_line = fl`. You want to ensure the first visible line is static in the end.

Cheers,
Mitchell

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Thu 13 Jul 2017 - 18:14:04 EDT

This archive was generated by hypermail 2.2.0 : Fri 14 Jul 2017 - 06:30:21 EDT