Skip to content

Commit

Permalink
nicer mouse behavior for foldwigets
Browse files Browse the repository at this point in the history
  activate on mousedown and on double click
  • Loading branch information
nightwing committed Nov 4, 2012
1 parent ebd4b5b commit e220a11
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/ace/mouse/default_gutter_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
Expand All @@ -14,7 +14,7 @@
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Expand Down
57 changes: 50 additions & 7 deletions lib/ace/mouse/fold_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
Expand All @@ -14,7 +14,7 @@
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Expand All @@ -32,24 +32,24 @@ define(function(require, exports, module) {
"use strict";

function FoldHandler(editor) {

editor.on("click", function(e) {
var position = e.getDocumentPosition();
var session = editor.session;

// If the user clicked on a fold, then expand it.
var fold = session.getFoldAt(position.row, position.column, 1);
if (fold) {
if (e.getAccelKey())
session.removeFold(fold);
else
session.expandFold(fold);

e.stop();
}
});
editor.on("gutterclick", function(e) {

editor.on("guttermousedown", function(e) {
var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);

if (gutterRegion == "foldWidgets") {
Expand All @@ -60,6 +60,49 @@ function FoldHandler(editor) {
e.stop();
}
});

editor.on("gutterdblclick", function(e) {
var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);

if (gutterRegion == "foldWidgets") {
var row = e.getDocumentPosition().row;
var session = editor.session;
var fw = session.foldWidgets;
if (!fw || fw[row])
return;

var i = row - 1, firstRange;
while (i >= 0) {
var c = fw[i];
if (c == null)
c = fw[i] = session.getFoldWidget();

if (c == "start") {
var range = session.getFoldWidgetRange(i);
if (!firstRange)
firstRange = range;
if (range && range.end.row >= row)
break;
}
i--;
}
if (i == -1)
range = firstRange;

if (range) {
var row = range.start.row;
var fold = session.getFoldAt(row, session.getLine(row).length, 1);

if (fold) {
session.removeFold(fold);
} else {
session.addFold("...", range);
editor.renderer.scrollCursorIntoView({row: range.start.row, column: 0});
}
}
e.stop();
}
});
}

exports.FoldHandler = FoldHandler;
Expand Down

0 comments on commit e220a11

Please sign in to comment.