<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://community.activestate.com" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>ActiveState Community Site - Komodo line selection macro - Comments</title>
 <link>http://community.activestate.com/forum-topic/komodo-line-selection-macro</link>
 <description>Comments for &quot;Komodo line selection macro&quot;</description>
 <language>en</language>
<item>
 <title>Komodo line selection macro</title>
 <link>http://community.activestate.com/forum-topic/komodo-line-selection-macro</link>
 <description>&lt;p&gt;I was recently asked if it was possible to turn a partial text selection inside the Komodo editor into a full line selection (similar to the way Vi&#039;s visual line selection works &quot;Shift-V&quot;).&lt;/p&gt;
&lt;p&gt;Indeed it is possible, though you&#039;ll need a Komodo macro to perform the functionality. Here is the Komodo JavaScript macro I came up with after a couple of minutes:&lt;/p&gt;
&lt;div class=&quot;geshi-block&quot;&gt;
&lt;div class=&quot;geshifilter javascript&quot; style=&quot;font-family: monospace;&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; scimoz = ko.&lt;span style=&quot;color: #006600;&quot;&gt;views&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;manager&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;currentView&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;scimoz&lt;/span&gt;;&lt;br /&gt;
&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;scimoz&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; anchorPos = scimoz.&lt;span style=&quot;color: #006600;&quot;&gt;anchor&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; currentPos = scimoz.&lt;span style=&quot;color: #006600;&quot;&gt;currentPos&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;// Line start/end positions will depend upon where the cursor is.&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;anchorPos &amp;lt; currentPos&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; scimoz.&lt;span style=&quot;color: #006600;&quot;&gt;anchor&lt;/span&gt; = scimoz.&lt;span style=&quot;color: #006600;&quot;&gt;positionFromLine&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;scimoz.&lt;span style=&quot;color: #006600;&quot;&gt;lineFromPosition&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;anchorPos&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; scimoz.&lt;span style=&quot;color: #006600;&quot;&gt;currentPos&lt;/span&gt; = Math.&lt;span style=&quot;color: #006600;&quot;&gt;max&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;scimoz.&lt;span style=&quot;color: #006600;&quot;&gt;getLineEndPosition&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;scimoz.&lt;span style=&quot;color: #006600;&quot;&gt;lineFromPosition&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;currentPos&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;scimoz.&lt;span style=&quot;color: #006600;&quot;&gt;positionFromLine&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;scimoz.&lt;span style=&quot;color: #006600;&quot;&gt;lineFromPosition&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;currentPos&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #CC0000;&quot;&gt;+1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; scimoz.&lt;span style=&quot;color: #006600;&quot;&gt;currentPos&lt;/span&gt; = scimoz.&lt;span style=&quot;color: #006600;&quot;&gt;positionFromLine&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;scimoz.&lt;span style=&quot;color: #006600;&quot;&gt;lineFromPosition&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;currentPos&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; scimoz.&lt;span style=&quot;color: #006600;&quot;&gt;anchor&lt;/span&gt; = Math.&lt;span style=&quot;color: #006600;&quot;&gt;max&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;scimoz.&lt;span style=&quot;color: #006600;&quot;&gt;getLineEndPosition&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;scimoz.&lt;span style=&quot;color: #006600;&quot;&gt;lineFromPosition&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;anchorPos&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;scimoz.&lt;span style=&quot;color: #006600;&quot;&gt;positionFromLine&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;scimoz.&lt;span style=&quot;color: #006600;&quot;&gt;lineFromPosition&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;anchorPos&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #CC0000;&quot;&gt;+1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;// To make the copy operation right here as well, uncomment the below lines.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;//var clipHelper = Components.classes[&amp;quot;@mozilla.org/widget/clipboardhelper;1&amp;quot;].getService(Components.interfaces.nsIClipboardHelper);&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;//clipHelper.copyString(String(scimoz.selText));&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;pre class=&quot;geshi-plain&quot;&gt;var scimoz = ko.views.manager.currentView.scimoz;
if (scimoz) {
    var anchorPos = scimoz.anchor;
    var currentPos = scimoz.currentPos;
    // Line start/end positions will depend upon where the cursor is.
    if (anchorPos &amp;lt; currentPos) {
        scimoz.anchor = scimoz.positionFromLine(scimoz.lineFromPosition(anchorPos));
        scimoz.currentPos = Math.max(scimoz.getLineEndPosition(scimoz.lineFromPosition(currentPos)),
                                     scimoz.positionFromLine(scimoz.lineFromPosition(currentPos)+1));
    } else {
        scimoz.currentPos = scimoz.positionFromLine(scimoz.lineFromPosition(currentPos));
        scimoz.anchor = Math.max(scimoz.getLineEndPosition(scimoz.lineFromPosition(anchorPos)),
                                 scimoz.positionFromLine(scimoz.lineFromPosition(anchorPos)+1));
    }

    // To make the copy operation right here as well, uncomment the below lines.

    //var clipHelper = Components.classes[&amp;quot;@mozilla.org/widget/clipboardhelper;1&amp;quot;].getService(Components.interfaces.nsIClipboardHelper);
    //clipHelper.copyString(String(scimoz.selText));
}&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Create a new JavaScript macro in your Komodo toolbox, with the above contents. You can then also assign the macro a specific keybinding to make it trigger when you need it to.&lt;/p&gt;
</description>
 <comments>http://community.activestate.com/forum-topic/komodo-line-selection-macro#comments</comments>
 <category domain="http://community.activestate.com/forums/komodo-discussion-0">Komodo discussion</category>
 <category domain="http://community.activestate.com/os/all-any">All / Any</category>
 <pubDate>Thu, 17 Apr 2008 15:51:28 -0700</pubDate>
 <dc:creator>ToddW</dc:creator>
 <guid isPermaLink="false">2206 at http://community.activestate.com</guid>
</item>
</channel>
</rss>
