<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Pythonscript set-selection question]]></title><description><![CDATA[<p dir="auto">It is my experience that whenever you have selected text, one end or the other of it will have a flashing cursor.  Thus, I was surprised to see that after executing some Pythonscript code that modifies a rectangular selection (user makes a column block, then invokes script), that what results (intended to be multiple single line blocks of various lengths, all starting at the original left column) has at least one odd selection which has no cursor touching it.  See video, at about 8 seconds the script is run:</p>
<p dir="auto"><img src="https://camo.nodebb.org/1080cd39eca98377570bdea1633848b99cf2e608?url=https%3A%2F%2Fi.imgur.com%2FkbfNF8W.gif" alt="" class=" img-fluid img-markdown" /></p>
<p dir="auto">The odd line is line 78 (and maybe line 84).  Is this a valid situation or some sort of bug?</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/14661/pythonscript-set-selection-question</link><generator>RSS for Node</generator><lastBuildDate>Fri, 12 Jun 2026 01:16:35 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/14661.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 19 Oct 2017 19:12:40 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Pythonscript set-selection question on Wed, 25 Oct 2017 15:29:03 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/claudia-frank" aria-label="Profile: Claudia-Frank">@<bdi>Claudia-Frank</bdi></a></p>
<p dir="auto">No worries, Claudia…I can let it go; it’s not that important…I withdraw the question(s).<br />
:)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/27611</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/27611</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Wed, 25 Oct 2017 15:29:03 GMT</pubDate></item><item><title><![CDATA[Reply to Pythonscript set-selection question on Tue, 24 Oct 2017 21:27:13 GMT]]></title><description><![CDATA[<blockquote>
<p dir="auto">I’d like to do the replacement and have selections on each line remain that reflect what happened during the replacement.</p>
</blockquote>
<p dir="auto">Not sure if this can be solved using selection functions but is it needed to have a selection<br />
or could you use indicators (like smart highlighting) instead?</p>
<p dir="auto">Cheers<br />
Claudia</p>
]]></description><link>https://community.notepad-plus-plus.org/post/27577</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/27577</guid><dc:creator><![CDATA[Claudia Frank]]></dc:creator><pubDate>Tue, 24 Oct 2017 21:27:13 GMT</pubDate></item><item><title><![CDATA[Reply to Pythonscript set-selection question on Mon, 23 Oct 2017 15:18:30 GMT]]></title><description><![CDATA[<p dir="auto">Well my original question was intended to be “How can I have some selected text without a blinking caret at one end of it or the other?”  Like on ine 78 in my gif.</p>
<p dir="auto">However, getting into my real goal…I’d like to do the replacement and have selections on each line remain that reflect what happened during the replacement.</p>
<p dir="auto">The partial line selections could either:</p>
<ul>
<li>get shorter (so the section for that line would reduce), possibly even down to zero (in which case only a blinking caret would remain in the column of the original rect block’s left side)</li>
<li>get longer (so the section for that line would extend)</li>
<li>stay the same length (in which case the selection highlight for a given line wouldn’t change)</li>
</ul>
<p dir="auto">So maybe this text:</p>
<p dir="auto">abcdefghijklmnopqrstuvwxyz<br />
abcdefghijklmnopqrstuvwxyz<br />
abcdefghijklmnopqrstuvwxyz<br />
abcdefghijklmnopqrstuvwxyz<br />
abcdefghijklmnopqrstuvwxyz</p>
<p dir="auto">gets column-selected by the user like this:</p>
<p dir="auto"><img src="https://camo.nodebb.org/b4f6c2ca110d74213d65e92865ab5278d8da1122?url=https%3A%2F%2Fi.imgur.com%2FLNI7eC6.jpg" alt="Imgur" class=" img-fluid img-markdown" /></p>
<p dir="auto">then a script runs a replacement and the desired selection after running looks something like this (note, just a selection demo as the text doesn’t change):</p>
<p dir="auto"><img src="https://camo.nodebb.org/ce9be3990e9144bf1ed439bc5d4aca1e131d6c45?url=https%3A%2F%2Fi.imgur.com%2FxgCE3Zf.jpg" alt="Imgur" class=" img-fluid img-markdown" /></p>
<p dir="auto">In this demo each line is consistent…a selection (starting in the column of the original rectangular block’s left side column) with blinking cursor at the right-end of the selection.</p>
<p dir="auto">I’m finding this difficult as I can get into situations like on line 78 and I don’t know what to think about that…I don’t know, I’ll keep experimenting with it.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/27551</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/27551</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Mon, 23 Oct 2017 15:18:30 GMT</pubDate></item><item><title><![CDATA[Reply to Pythonscript set-selection question on Fri, 20 Oct 2017 21:35:49 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a></p>
<p dir="auto">Alan, what I was thinking about it is something like this.<br />
Assuming a text like</p>
<pre><code>'''
abc-abc-abc
b
bb
bbb
bbbb
bbb
abc-abbbc-abc
abc-abc-abc
'''
</code></pre>
<p dir="auto">with a rectangular selection of (8, 49)</p>
<p dir="auto"><img src="https://camo.nodebb.org/16ffa3dafc255c6b942e7d9660898c3d291f6b6d?url=https%3A%2F%2Fi.imgur.com%2Ff68hesO.png" alt="" class=" img-fluid img-markdown" /></p>
<p dir="auto">and you want to replace ‘bb’ within the selection with a code like this</p>
<pre><code>user_selection = editor.getUserCharSelection()
for i in xrange(editor.getSelections()):
    editor.setTargetStart(editor.getSelectionNStart(i))
    editor.setTargetEnd(editor.getSelectionNEnd(i))
    if editor.searchInTarget('bb') &gt; -1:
        editor.replaceTarget(editor.getTextRange(editor.getTargetStart(), editor.getTargetEnd()).replace('bb',''))
</code></pre>
<p dir="auto">will result in</p>
<p dir="auto"><img src="https://camo.nodebb.org/4449b307022d297ed30cb47d6693dcb2717751af?url=https%3A%2F%2Fi.imgur.com%2FxbKS47W.png" alt="" class=" img-fluid img-markdown" /></p>
<p dir="auto">because parts of the selections have been replaced. Now it depends what you want to achieve<br />
because if you want to have the initial selection parameters and add code like</p>
<pre><code>editor.setRectangularSelectionAnchor(user_selection[0])
editor.setRectangularSelectionCaret(user_selection[1])
</code></pre>
<p dir="auto">after replacement code, selection will expand.</p>
<p dir="auto"><img src="https://camo.nodebb.org/c35a218cbce7c66d3d0ffb586032cb356056786d?url=https%3A%2F%2Fi.imgur.com%2FIIeoMk8.png" alt="" class=" img-fluid img-markdown" /></p>
<p dir="auto">So you might consider reducing the resulting selection by the amount of text to be replaced.</p>
<p dir="auto">Makes this sense to you? Or did I misunderstood your initial question?</p>
<p dir="auto">Cheers<br />
Claudia</p>
]]></description><link>https://community.notepad-plus-plus.org/post/27530</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/27530</guid><dc:creator><![CDATA[Claudia Frank]]></dc:creator><pubDate>Fri, 20 Oct 2017 21:35:49 GMT</pubDate></item><item><title><![CDATA[Reply to Pythonscript set-selection question on Fri, 20 Oct 2017 13:26:07 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/claudia-frank" aria-label="Profile: Claudia-Frank">@<bdi>Claudia-Frank</bdi></a></p>
<p dir="auto">Hello Claudia!</p>
<p dir="auto">Yes it is a replace operation and yes virtual space can be in play here.  My goal is to analyze what changed from the replace and then set new multiple selections based upon that.  Note that before the script is run we have a true rectangular block (which may contain virtual spaces).  Afterward it won’t be that any more but will be “N” selections of various “widths”, on “N” consecutive lines (N=height of pre-script-run column selection).  Maybe I’m just doing it wrong.  Do I have to set the selection to “nothing” before beginning to set a different selection(s)?</p>
<p dir="auto">I’m not sure what you mean by “recalculate the selection afterwards”.  For each line I grab original content into a variable, then do the replace, then compare the line’s new content to the original to determine how I want to set the selection I will leave active for that line.</p>
<p dir="auto">Any hints would be great as I find “selection-set” stuff a bit hard to understand in PS!</p>
<p dir="auto">A related question is how to actually set a true rectangular selection in code.  Whenever I’ve tried to do this, actions performed after it seem like they are acting on “N” different selections of stream type, not one selection of rectangular type.  I can’t be more specific right now but I know this has come up for me in the past.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/27516</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/27516</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Fri, 20 Oct 2017 13:26:07 GMT</pubDate></item><item><title><![CDATA[Reply to Pythonscript set-selection question on Fri, 20 Oct 2017 11:33:50 GMT]]></title><description><![CDATA[<p dir="auto">Hi Alan,</p>
<p dir="auto">the gif indicates that this happens after a replace operation, is this the case?<br />
If so, did you recalculate the selection afterwards? Do you mess with virtualspaceoptions?</p>
<p dir="auto">Cheers<br />
Claudia</p>
]]></description><link>https://community.notepad-plus-plus.org/post/27512</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/27512</guid><dc:creator><![CDATA[Claudia Frank]]></dc:creator><pubDate>Fri, 20 Oct 2017 11:33:50 GMT</pubDate></item></channel></rss>