nicer mouse behavior for foldwigets
activate on mousedown and on double click
This commit is contained in:
parent
ebd4b5bfaa
commit
e220a11f34
2 changed files with 52 additions and 9 deletions
|
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* Copyright (c) 2010, Ajax.org B.V.
|
* Copyright (c) 2010, Ajax.org B.V.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
* * Redistributions of source code must retain the above copyright
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
* * Neither the name of Ajax.org B.V. nor the
|
* * Neither the name of Ajax.org B.V. nor the
|
||||||
* names of its contributors may be used to endorse or promote products
|
* names of its contributors may be used to endorse or promote products
|
||||||
* derived from this software without specific prior written permission.
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
* 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
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* Copyright (c) 2010, Ajax.org B.V.
|
* Copyright (c) 2010, Ajax.org B.V.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
* * Redistributions of source code must retain the above copyright
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
* * Neither the name of Ajax.org B.V. nor the
|
* * Neither the name of Ajax.org B.V. nor the
|
||||||
* names of its contributors may be used to endorse or promote products
|
* names of its contributors may be used to endorse or promote products
|
||||||
* derived from this software without specific prior written permission.
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
* 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
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
|
@ -32,11 +32,11 @@ define(function(require, exports, module) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function FoldHandler(editor) {
|
function FoldHandler(editor) {
|
||||||
|
|
||||||
editor.on("click", function(e) {
|
editor.on("click", function(e) {
|
||||||
var position = e.getDocumentPosition();
|
var position = e.getDocumentPosition();
|
||||||
var session = editor.session;
|
var session = editor.session;
|
||||||
|
|
||||||
// If the user clicked on a fold, then expand it.
|
// If the user clicked on a fold, then expand it.
|
||||||
var fold = session.getFoldAt(position.row, position.column, 1);
|
var fold = session.getFoldAt(position.row, position.column, 1);
|
||||||
if (fold) {
|
if (fold) {
|
||||||
|
|
@ -44,12 +44,12 @@ function FoldHandler(editor) {
|
||||||
session.removeFold(fold);
|
session.removeFold(fold);
|
||||||
else
|
else
|
||||||
session.expandFold(fold);
|
session.expandFold(fold);
|
||||||
|
|
||||||
e.stop();
|
e.stop();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
editor.on("gutterclick", function(e) {
|
editor.on("guttermousedown", function(e) {
|
||||||
var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);
|
var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);
|
||||||
|
|
||||||
if (gutterRegion == "foldWidgets") {
|
if (gutterRegion == "foldWidgets") {
|
||||||
|
|
@ -60,6 +60,49 @@ function FoldHandler(editor) {
|
||||||
e.stop();
|
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;
|
exports.FoldHandler = FoldHandler;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue