Page 1 of 1

Get item at position

Posted: 26 Apr 2016 20:43
by tiago
Trying to optimize my navigational capabilities I see it would be very useful to be able to retrieve an item's path by its position in list. More to the point, i'm interested in an item's immediate neighbors. This would save heavy and clumsy full list retrieval. Itematpos() sounded a natural place for it, but it's coordinate driven. Get() enhancement, please...?

Re: Get item at position

Posted: 26 Apr 2016 21:23
by highend
Could be scripted as a function (with the next beta)... :)

E.g.:
This would show the 5 leading, the file itself + the next 5 following items (for the current active pane):

Code: Select all

    text FindNeighbours(7, 5);

function FindNeighbours($pos=1, $range=1) {
    $items    = listpane(, , , <crlf>);
    $count    = gettoken($items, "count", <crlf>);
    $firstPos = ($pos - $range < 1) ? 1 : $pos - $range;
    $lastPos  = ($pos + $range > $count) ? $count : $pos + $range;
    return gettoken(gettoken($items, $firstPos, <crlf>, , 2), $lastPos - $firstPos + 1, <crlf>, , 1);
}

Re: Get item at position

Posted: 27 Apr 2016 08:58
by admin
tiago wrote:Trying to optimize my navigational capabilities I see it would be very useful to be able to retrieve an item's path by its position in list. More to the point, i'm interested in an item's immediate neighbors. This would save heavy and clumsy full list retrieval. Itematpos() sounded a natural place for it, but it's coordinate driven. Get() enhancement, please...?
Good idea. :tup:

Just did it:

Code: Select all

    + SC get("item") enhanced: Added an optional parameter to pass the position 
      of the item in the list (the first position is "1"). If missing the 
      focused item is returned.
      Syntax: get("Item", [pane=a], [pos])
      Examples:
        echo get("item", , 4); //item at position 4
      Also works as variable:
        echo <get item  4>; //note the 2 spaces! the "pane" parameter is missing