{"id":3251,"date":"2014-02-23T16:04:07","date_gmt":"2014-02-23T22:04:07","guid":{"rendered":"http:\/\/bililite.com\/blog\/?p=3251"},"modified":"2014-02-23T16:04:07","modified_gmt":"2014-02-23T22:04:07","slug":"new-features-for-bililiterange","status":"publish","type":"post","link":"https:\/\/bililite.com\/blog\/2014\/02\/23\/new-features-for-bililiterange\/","title":{"rendered":"New features for <code>bililiteRange<\/code>"},"content":{"rendered":"<p>I liked the way <a href=\"http:\/\/dabblet.com\/\">Dabblet<\/a> does autoindenting (entering a new line copies the whitespace from the beginning of the current line, so you keep the same level of indentation). So I added an option to <code class=\"language-javascript\" >bililiteRange(element).text()<\/code> to do that. Now <code class=\"language-javascript\" >bililiteRange(element).text('text to insert', select, true)<\/code> with <code class=\"language-javascript\" >true<\/code> passed as the last option will autoindent. My <a href=\"\/blog\/blogfiles\/prism\/prismeditor.html\">Prism editor<\/a> now has a check box to implement that.<\/p>\r\n<p>The code to do this is in the <a href=\"https:\/\/github.com\/dwachss\/bililiteRange\/blob\/master\/bililiteRange.util.js\">bililiteRange utilities<\/a>, not the original code.<\/p>\r\n<p>I also added two more bililiteRange plugins:<\/p>\r\n<dl>\r\n<dt><code class=\"language-javascript\" >bililiteRange(element).indent(tabs)<\/code><\/dt>\r\n<dd>Prepends the string <code class=\"language-javascript\" >tabs<\/code> to each line that contains part of the range. Thus <code class=\"language-javascript\" >bililiteRange(element).bounds('selection').indent('\\t')<\/code> to indent by one tab (and if you want spaces, use those instead; I won't get into <a href=\"http:\/\/c2.com\/cgi\/wiki?TabsVersusSpaces\">Holy Wars<\/a>).<\/dd>\r\n<dt><code class=\"language-javascript\" >bililiteRange(element).unindent(n, tabSize)<\/code><\/dt>\r\n<dd>Removes <code class=\"language-javascript\" >n<\/code> tab characters or sequences of <code class=\"language-javascript\" >tabSize<\/code> spaces from the start of each line.<\/dd>\r\n<\/dl>\r\n\r\n<p>And, inspired by <a href=\"http:\/\/api.jquery.com\/data\/\">jQuery <code class=\"language-javascript\" >data<\/code><\/a>, added a <code class=\"language-javascript\" >bililiteRange(element).data()<\/code> that returns an object tied to <code class=\"language-javascript\" >element<\/code> that can be used to store any data on that element (not the bililiteRange) without memory leaks. Thus <code class=\"language-javascript\" >bililiteRange(element).data().tabSize = 4<\/code> can be used in future calls: <code class=\"language-javascript\" >assert(bililiteRange(element).data().tabSize == 4)<\/code>. In fact, <code class=\"language-javascript\" >unindent<\/code> above does exactly that if <code class=\"language-javascript\" >tabSize<\/code> is not passed in.<\/p>","protected":false},"excerpt":{"rendered":"I liked the way Dabblet does autoindenting (entering a new line copies the whitespace from the beginning of the current line, so you keep the same level of indentation). So I added an option to bililiteRange(element).text() to do that. Now bililiteRange(element).text('text to insert', select, true) with true passed as the last option will autoindent. My [&hellip;]","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,10],"tags":[],"_links":{"self":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts\/3251"}],"collection":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/comments?post=3251"}],"version-history":[{"count":3,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts\/3251\/revisions"}],"predecessor-version":[{"id":3254,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts\/3251\/revisions\/3254"}],"wp:attachment":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/media?parent=3251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/categories?post=3251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/tags?post=3251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}