Handle ranges for quick edit TextRange

This commit is contained in:
Swagatam Mitra committed 2017-04-26 08:37:12 +05:30
1 parent 23a2644819
commit 2afb592c19
4 files changed
+80 -28

No files matched your search

+20 -15
View File
@@ -150,7 +150,9 @@ define(function (require, exports, module) {
if (matchedSelector) {
var range = {
startLine: matchedSelector.position.start.line - 1,
endLine: matchedSelector.position.end.line - 1
endLine: matchedSelector.position.end.line - 1,
startChar: matchedSelector.position.start.column - 1,
endChar: matchedSelector.position.end.column - 1
};
inlineInfo = EditorManager.createInlineEditorForDocument(doc, range, $("#livedata-tools .inline-editor-holder"));
@@ -186,15 +188,25 @@ define(function (require, exports, module) {
console.warn(info);
}
function _consolidateRules(ruleArr) {
function _createGlobalCSSSearchHandler(consolidatedRanges) {
brackets.connected = true;
brackets.findMatchingRules = function () {
var $deferred = $.Deferred();
$deferred.resolve(consolidatedRanges);
return $deferred.promise();
};
}
/*function _consolidateRules(ruleArr) {
var files = Object.keys(ruleArr), rules;
var fIndex, file, rIndex, rule, $entry, consolidatedRanges = [];
var fIndex, file, rule, $entry, consolidatedRanges = [];
for (fIndex in files) {
if (files.hasOwnProperty(fIndex)) {
file = files[fIndex];
rules = ruleArr[file];
DocumentManager.getDocumentForPath(ProjectManager.getProjectRoot()._path + file.substring(1)).done(function (doc) {
var rIndex;
for (rIndex in rules) {
if (rules.hasOwnProperty(rIndex)) {
rule = rules[rIndex];
@@ -205,19 +217,12 @@ define(function (require, exports, module) {
}
}
if (Object.keys(ruleArr).length === 0) {
//_createMultiRangeInlineEditor(consolidatedRanges);
brackets.connected = true;
brackets.findMatchingRules = function () {
var $deferred = $.Deferred();
$deferred.resolve(consolidatedRanges);
return $deferred.promise();
}
//CommandManager.execute(Commands.TOGGLE_QUICK_EDIT);
_createGlobalCSSSearchHandler(consolidatedRanges);
}
});
}
}
}
}*/
$(window.document).on("click", "#livedata-tools .related > ul > li", function () {
_handleInlineEdit($(this));
@@ -248,7 +253,7 @@ define(function (require, exports, module) {
$("#livedata-tools .related > ul > li:nth-child(2)").addClass("selected");
_handleInlineEdit($("#livedata-tools .related > ul > li:nth-child(2)"));
_consolidateRules(ruleArr);
//_consolidateRules(ruleArr);
}
WebSocketTransportDomain.on("livedata", function (obj, message) {
@@ -259,7 +264,7 @@ define(function (require, exports, module) {
$("#livedata-tools").show();
$("#livedata-tools #breadcrumb").show();
_processNodePath(JSON.parse(message.path));
_processLiveData/*_consolidateRules*/(JSON.parse(message.data));
_processLiveData(JSON.parse(message.data));
}
});
@@ -272,7 +277,7 @@ define(function (require, exports, module) {
return "";
});
$(document).on("change", "#related-toggle", function () {
$(window.document).on("change", "#related-toggle", function () {
//CommandManager.execute(Commands.FILE_REFRESH);
ProjectManager.rerenderTree();
});
+1 -2
View File
@@ -38,8 +38,7 @@
}
.not-in-preview {
display:none !important;
opacity:0.6 !important;
opacity:0.5 !important;
}
.not-in-preview .not-in-preview{
+3 -1
View File
@@ -55,9 +55,11 @@ define(function (require, exports, module) {
* @param {number} startLine First line in range (0-based, inclusive)
* @param {number} endLine Last line in range (0-based, inclusive)
*/
function TextRange(document, startLine, endLine) {
function TextRange(document, startLine, endLine, startChar, endChar) {
this.startLine = startLine;
this.endLine = endLine;
this.startChar = startChar;
this.endChar = endChar;
this.document = document;
document.addRef();
+56 -10
View File
@@ -332,7 +332,7 @@ define(function (require, exports, module) {
var $container = $(container);
if (range) { // attach this first: want range updated before we process a change
this._visibleRange = new TextRange(document, range.startLine, range.endLine);
this._visibleRange = new TextRange(document, range.startLine, range.endLine, range.startChar, range.endChar);
}
// store this-bound version of listeners so we can remove them later
@@ -849,18 +849,41 @@ define(function (require, exports, module) {
if (this._visibleRange) {
var cm = this._codeMirror,
self = this;
cm.operation(function () {
self._hideMarks.forEach(function (mark) {
if (mark) {
mark.clear();
}
if (this._visibleRange.startChar && this._visibleRange.endChar) {
this._updateHiddenRanges();
} else {
cm.operation(function () {
self._hideMarks.forEach(function (mark) {
if (mark) {
mark.clear();
}
});
self._hideMarks = [];
self._hideMarks.push(self._hideLines(0, self._visibleRange.startLine));
self._hideMarks.push(self._hideLines(self._visibleRange.endLine + 1, self.lineCount()));
});
self._hideMarks = [];
self._hideMarks.push(self._hideLines(0, self._visibleRange.startLine));
self._hideMarks.push(self._hideLines(self._visibleRange.endLine + 1, self.lineCount()));
});
}
}
};
/**
* Ensures that the lines that are actually hidden in the inline editor correspond to
* the desired visible range.
*/
Editor.prototype._updateHiddenRanges = function () {
var cm = this._codeMirror,
self = this;
cm.operation(function () {
self._hideMarks.forEach(function (mark) {
if (mark) {
mark.clear();
}
});
self._hideMarks = [];
self._hideMarks.push(self._hideRange({line: 0, ch: 0}, {line: self._visibleRange.startLine, ch: self._visibleRange.startChar}));
self._hideMarks.push(self._hideRange({line: self._visibleRange.endLine, ch: self._visibleRange.endChar}, {line: self.lineCount(), ch: Number.MAX_SAFE_INTEGER}));
});
};
Editor.prototype._applyChanges = function (changeList) {
// _visibleRange has already updated via its own Document listener. See if this change caused
@@ -1549,6 +1572,29 @@ define(function (require, exports, module) {
return value;
};
/* Hides the specified line number in the editor
* @param {!from} line to start hiding from (inclusive)
* @param {!to} line to end hiding at (exclusive)
* @return {TextMarker} The CodeMirror mark object that's hiding the lines
*/
Editor.prototype._hideRange = function (from, to) {
/*if (to <= from) {
return;
}*/
// We set clearWhenEmpty: false so that if there's a blank line at the beginning or end of
// the document, and that's the only hidden line, we can still actually hide it. Doing so
// requires us to create a 0-length marked span, which would ordinarily be cleaned up by CM
// if clearWithEmpty is true. See https://groups.google.com/forum/#!topic/codemirror/RB8VNF8ow2w
var value = this._codeMirror.markText(
from,
to,
{collapsed: true, inclusiveLeft: true, inclusiveRight: true, clearWhenEmpty: false}
);
return value;
};
/**
* Gets the total height of the document in pixels (not the viewport)