Those two lines of code; mine and your proposed alternative are not equivalent: A structural node could contain comments, which the proposed alternative would not remove.



On Thursday, December 19, 2013 5:05 PM, Pavel Strashkin <notifications@github.com> wrote:
 
In app/scripts/services/lightweight-dom.js:
> +     * matches the behavior of the shelf and autocomplete features. It is, admittedly, a little
> +     * bit obscure but based on all editor use cases we've looked at, it works.
> +     *
> +     * @param editor The CodeMirror raml editor containing the RAML document
> +     * @param lineNum The line to read the node from. Current editor cursor line if not specified.
> +     * @returns {Number} Number of tabs at line or at cursor
> +     */
> +    function getTabCount(editor, lineNum, nodeIsStructural) {
> +      //Special case: If the current line is where the cursor is, AND
> +      //the line is non-structural, then the tab count is based on the
> +      //cursor position, not the contents of the line:
> +      var line = editor.getLine(lineNum);
> +      if (!nodeIsStructural) {
> +        var cursor = editor.getCursor();
> +        if (cursor.line === lineNum) {
> +          line = ((new Array(cursor.ch + 1)).join(' ')); //<- Line containing spaces up to cursor 
As JS uses swallow copies for strings, it'd be better to do line = line.slice(0, cursor.ch) instead of creating a new array.
—
Reply to this email directly or view it on GitHub.