ActiveState Powered by ActiveState

ActiveState Community


Soft characters in beta 5

Posted by bcorfman on 2007-08-01 12:22
OS: All / Any

I find this feature promising but I think it needs more work. What I was intuitively looking for when I tried it was the same feature that is in Eclipse: once the soft character(s) appear, hitting ENTER hardens the remaining soft characters on the line and moves the cursor directly after the just-completed characters. Reaching for the right-arrow key instead is slow, IMO, plus it only hardens one character at a time. It looks like hitting the END key is a partial solution (since you don't always want to complete to the end of the line), but it's also just about as difficult to hit as the right arrow.

ericp | Wed, 2007-08-01 17:18

We looked at TextMate as well as Eclipse to see how other editors were
implementing this feature. I also used to run Visual Studio with the
CSharper extension, which did similar things.

Good points on how to handle pressing return. The return-key is usually
one of the larger keys on the keyboard, and unlike the End-key people
can find it quickly. All the more reason for using it to move to the
end of the line. I like how we're handling presses of return between
the braces though. I think that Eclipse might be doing the right thing
with typed open-braces -- nothing. If you press return after a "{",
it appends a close-brace on an extra line unless there's already one
in place, which works most of the time.

We've tried for a relatively simple scheme for how soft characters work,
because we don't want them to get in the way. If you have to stop and
constantly check whether soft chars have been inserted, or hardened, it'll
take your mind off the task at hand. Do you find that's happening here?

bcorfman | Thu, 2007-08-02 05:53

We've tried for a relatively simple scheme for how soft characters work,
because we don't want them to get in the way. If you have to stop and
constantly check whether soft chars have been inserted, or hardened, it'll
take your mind off the task at hand. Do you find that's happening here?

What is your goal for soft characters? Is it to simply keep track of closing braces/parens for the user? Or is it to offer an easier way to complete ending characters?

I thought that the existing functionality of highlighting matching braces/parens was enough for me to keep track of what I'm doing, so when I saw your new feature, I was looking for an easier way to complete ending characters. I think the ENTER key is by far the most natural key for me to use because it's one press to harden characters and then a second press to go to the next line (which is a pretty typical scenario).

I find that trying to locate the End-key or right-arrow is taking me more off-task because I keep hitting the wrong key, or I have to slow down to make sure I hit the correct key. This takes away all the advantages of the character completion for me. Right now, I find it smoother to just turn off the feature, and I suspect that's not what you hoped for. :)

ericp | Wed, 2007-08-01 18:06

You invoke this macro when you've just typed a character, the rest of
the line consists of soft characters, and you
want to move that character to the end of the line. I found since this
is a transposition of sorts that it made sense to rebind Ctrl-T
from the Transpose Current and Previous Characters to this macro, and
if the conditions don't hold, it calls the underlying function.

Bonus hack: if the character is a "{", it inserts a space before it.
When I looked at the ASCII table I couldn't think of other characters
where this made sense.

Unfortunate part:

If you've typed this text:

if (f(g(1|))

where your cursor is the vertical bar after the "1" and both ")"s are soft,
and then you type a "{", Komodo will insert a soft close brace after it, which
you need to delete. The way Eclipse handles braces is looking better.

Here's the macro. I call it "transpose-soft-characters", and bind it to Ctrl-T:

(function(komodo, scimoz) {
    var f = function(komodo, scimoz) {
        var currPos = scimoz.currentPos;
        if (currPos == 0) {
            return false;
        }
        var prevPos = scimoz.positionBefore(currPos);
        var prevChar = scimoz.getWCharAt(prevPos);
        var _softCharDecorator = Components.interfaces.koILintResult.DECORATOR_SOFT_CHAR;
        if (!scimoz.indicatorValueAt(_softCharDecorator, currPos)) {
            return false;
        }
        var currLine = scimoz.lineFromPosition(currPos);
        var lineEndPos = scimoz.getLineEndPosition(currLine);
        scimoz.indicatorCurrent = _softCharDecorator;
        scimoz.indicatorClearRange(currPos, lineEndPos - currPos);
        scimoz.deleteBack();
        scimoz.lineEnd();
        var newStr = (prevChar == "{" ? " " : "") + prevChar;
        scimoz.insertText(scimoz.currentPos, newStr);
        scimoz.lineEnd();
        if (komodo.view.scintilla) { komodo.view.scintilla.focus(); }
        return true;
    };
    scimoz.beginUndoAction();
    try {
        if (!f(komodo, scimoz)) {
            // Uncomment the next line if you bind this function to Ctrl-T
            komodo.doCommand('cmd_transpose');
        }
    } finally {
        scimoz.endUndoAction();
    }
})(komodo, komodo.editor);
(function(komodo, scimoz) {
    var f = function(komodo, scimoz) {
        var currPos = scimoz.currentPos;
        if (currPos == 0) {
            return false;
        }
        var prevPos = scimoz.positionBefore(currPos);
        var prevChar = scimoz.getWCharAt(prevPos);
        var _softCharDecorator = Components.interfaces.koILintResult.DECORATOR_SOFT_CHAR;
        if (!scimoz.indicatorValueAt(_softCharDecorator, currPos)) {
            return false;
        }
        var currLine = scimoz.lineFromPosition(currPos);
        var lineEndPos = scimoz.getLineEndPosition(currLine);
        scimoz.indicatorCurrent = _softCharDecorator;
        scimoz.indicatorClearRange(currPos, lineEndPos - currPos);
        scimoz.deleteBack();
        scimoz.lineEnd();
        var newStr = (prevChar == "{" ? " " : "") + prevChar;
        scimoz.insertText(scimoz.currentPos, newStr);
        scimoz.lineEnd();
        if (komodo.view.scintilla) { komodo.view.scintilla.focus(); }
        return true;
    };
    scimoz.beginUndoAction();
    try {
        if (!f(komodo, scimoz)) {
            // Uncomment the next line if you bind this function to Ctrl-T
            komodo.doCommand('cmd_transpose');
        }
    } finally {
        scimoz.endUndoAction();
    }
})(komodo, komodo.editor);
-->