Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master-up' into in-browser
Browse files Browse the repository at this point in the history
  • Loading branch information
jdiehl committed Oct 18, 2012
2 parents 10189e3 + 6a034b2 commit 9180c43
Show file tree
Hide file tree
Showing 36 changed files with 1,072 additions and 375 deletions.
19 changes: 5 additions & 14 deletions src/LiveDevelopment/LiveDevelopment.js
Expand Up @@ -162,15 +162,6 @@ define(function LiveDevelopment(require, exports, module) {
}
}

/** Determine whether the given document is an HTML file
* by checking its extension.
* @param {Document} document to check
* @return {boolean} true if the given document's extension has "htm", false otherwise.
*/
function _isHTMLDocument(doc) {
return (doc && doc.extension.indexOf("htm") !== -1);
}

/**
* Removes the given CSS/JSDocument from _relatedDocuments. Signals that the
* given file is no longer associated with the HTML document that is live (e.g.
Expand Down Expand Up @@ -331,7 +322,7 @@ define(function LiveDevelopment(require, exports, module) {
status = STATUS_ACTIVE;

_openDocument(doc, editor);
if (doc.isDirty && _isHTMLDocument(doc)) {
if (doc.isDirty && _classForDocument(doc) !== CSSDocument) {
status = STATUS_OUT_OF_SYNC;
}
_setStatus(status);
Expand Down Expand Up @@ -501,7 +492,7 @@ define(function LiveDevelopment(require, exports, module) {
}
}

if (doc.isDirty && _isHTMLDocument(doc)) {
if (doc.isDirty && _classForDocument(doc) !== CSSDocument) {
status = STATUS_OUT_OF_SYNC;
}
_setStatus(status);
Expand All @@ -511,8 +502,8 @@ define(function LiveDevelopment(require, exports, module) {
/** Triggered by a document saved from the DocumentManager */
function _onDocumentSaved() {
var doc = _getCurrentDocument();

if (doc && _classForDocument(doc) !== CSSDocument && Inspector.connected()) {
if (doc && Inspector.connected() && _classForDocument(doc) !== CSSDocument) {
if (agents.network && agents.network.wasURLRequested(doc.url)) {
// Reload HTML page
Inspector.Page.reload();
Expand All @@ -528,7 +519,7 @@ define(function LiveDevelopment(require, exports, module) {

/** Triggered by a change in dirty flag from the DocumentManager */
function _onDirtyFlagChange(event, doc) {
if (doc && doc.isDirty && _isHTMLDocument(doc) && Inspector.connected()) {
if (Inspector.connected() && doc && doc.isDirty && _classForDocument(doc) !== CSSDocument) {
if (agents.network && agents.network.wasURLRequested(doc.url)) {
// Set status to out of sync
_setStatus(STATUS_OUT_OF_SYNC);
Expand Down
5 changes: 4 additions & 1 deletion src/brackets.js
Expand Up @@ -158,6 +158,7 @@ define(function (require, exports, module) {
CodeHintManager : CodeHintManager,
CSSUtils : require("language/CSSUtils"),
LiveDevelopment : require("LiveDevelopment/LiveDevelopment"),
DOMAgent : require("LiveDevelopment/Agents/DOMAgent"),
Inspector : require("LiveDevelopment/Inspector/Inspector"),
NativeApp : require("utils/NativeApp"),
ExtensionUtils : require("utils/ExtensionUtils"),
Expand Down Expand Up @@ -243,7 +244,9 @@ define(function (require, exports, module) {
// WARNING: AppInit.appReady won't fire if ANY extension fails to
// load or throws an error during init. To fix this, we need to
// make a change to _initExtensions (filed as issue 1029)
_initExtensions().always(AppInit._dispatchReady(AppInit.APP_READY));
_initExtensions().always(function () {
AppInit._dispatchReady(AppInit.APP_READY);
});

// If this is the first launch, and we have an index.html file in the project folder (which should be
// the samples folder on first launch), open it automatically. (We explicitly check for the
Expand Down
2 changes: 2 additions & 0 deletions src/command/Commands.js
Expand Up @@ -62,6 +62,7 @@ define(function (require, exports, module) {
exports.EDIT_INDENT = "edit.indent";
exports.EDIT_UNINDENT = "edit.unindent";
exports.EDIT_DUPLICATE = "edit.duplicate";
exports.EDIT_DELETE_LINES = "edit.deletelines";
exports.EDIT_LINE_COMMENT = "edit.lineComment";
exports.EDIT_LINE_UP = "edit.lineUp";
exports.EDIT_LINE_DOWN = "edit.lineDown";
Expand All @@ -77,6 +78,7 @@ define(function (require, exports, module) {
// Navigate
exports.NAVIGATE_NEXT_DOC = "navigate.nextDoc";
exports.NAVIGATE_PREV_DOC = "navigate.prevDoc";
exports.NAVIGATE_SHOW_IN_FILE_TREE = "navigate.showInFileTree";
exports.NAVIGATE_QUICK_OPEN = "navigate.quickOpen";
exports.NAVIGATE_GOTO_DEFINITION = "navigate.gotoDefinition";
exports.NAVIGATE_GOTO_LINE = "navigate.gotoLine";
Expand Down
6 changes: 3 additions & 3 deletions src/command/KeyBindingManager.js
Expand Up @@ -126,13 +126,13 @@ define(function (require, exports, module) {
right = right.trim().toLowerCase();
var matched = (left.length > 0 && left === right);
if (matched && previouslyFound) {
console.log("KeyBindingManager normalizeKeyDescriptorString() - Modifier defined twice: " + origDescriptor);
console.log("KeyBindingManager normalizeKeyDescriptorString() - Modifier " + left + " defined twice: " + origDescriptor);
}
return matched;
}

origDescriptor.split("-").forEach(function parseDescriptor(ele, i, arr) {
if (_compareModifierString("ctrl", ele, hasCtrl)) {
if (_compareModifierString("ctrl", ele, hasCtrl, origDescriptor)) {
if (brackets.platform === "mac") {
hasMacCtrl = true;
} else {
Expand Down Expand Up @@ -326,7 +326,7 @@ define(function (require, exports, module) {
// skip if the key is already assigned
if (_isKeyAssigned(normalized)) {
console.log("Cannot assign " + normalized + " to " + commandID +
". It is already assigned to " + _keyMap[normalized]);
". It is already assigned to " + _keyMap[normalized].commandID);
return null;
}

Expand Down
3 changes: 3 additions & 0 deletions src/command/Menus.js
Expand Up @@ -883,6 +883,7 @@ define(function (require, exports, module) {
menu.addMenuItem(Commands.EDIT_INDENT, [{key: "Indent", displayKey: "Tab"}]);
menu.addMenuItem(Commands.EDIT_UNINDENT, [{key: "Unindent", displayKey: "Shift-Tab"}]);
menu.addMenuItem(Commands.EDIT_DUPLICATE, "Ctrl-D");
menu.addMenuItem(Commands.EDIT_DELETE_LINES, "Ctrl-Shift-D");
menu.addMenuItem(Commands.EDIT_LINE_UP, [{key: "Ctrl-Shift-Up", displayKey: "Ctrl-Shift-\u2191",
platform: "win"},
{key: "Cmd-Ctrl-Up", displayKey: "Cmd-Ctrl-\u2191",
Expand Down Expand Up @@ -923,6 +924,8 @@ define(function (require, exports, module) {
menu.addMenuItem(Commands.NAVIGATE_PREV_DOC, [{key: "Ctrl-Shift-Tab", platform: "win"},
{key: "Ctrl-Shift-Tab", platform: "mac"}]);
menu.addMenuDivider();
menu.addMenuItem(Commands.NAVIGATE_SHOW_IN_FILE_TREE);
menu.addMenuDivider();
menu.addMenuItem(Commands.TOGGLE_QUICK_EDIT, "Ctrl-E");
menu.addMenuItem(Commands.QUICK_EDIT_PREV_MATCH, {key: "Alt-Up", displayKey: "Alt-\u2191"});
menu.addMenuItem(Commands.QUICK_EDIT_NEXT_MATCH, {key: "Alt-Down", displayKey: "Alt-\u2193"});
Expand Down
12 changes: 9 additions & 3 deletions src/document/DocumentCommandHandlers.js
Expand Up @@ -811,6 +811,10 @@ define(function (require, exports, module) {
goNextPrevDoc(-1);
}

function handleShowInTree() {
ProjectManager.showInTree(DocumentManager.getCurrentDocument().file);
}


function init($titleContainerToolbar) {
_$titleContainerToolbar = $titleContainerToolbar;
Expand All @@ -828,16 +832,18 @@ define(function (require, exports, module) {
CommandManager.register(Strings.CMD_FILE_NEW_FOLDER, Commands.FILE_NEW_FOLDER, handleNewFolderInProject);
CommandManager.register(Strings.CMD_FILE_SAVE, Commands.FILE_SAVE, handleFileSave);
CommandManager.register(Strings.CMD_FILE_SAVE_ALL, Commands.FILE_SAVE_ALL, handleFileSaveAll);

CommandManager.register(Strings.CMD_FILE_RENAME, Commands.FILE_RENAME, handleFileRename);

CommandManager.register(Strings.CMD_FILE_CLOSE, Commands.FILE_CLOSE, handleFileClose);
CommandManager.register(Strings.CMD_FILE_CLOSE_ALL, Commands.FILE_CLOSE_ALL, handleFileCloseAll);
CommandManager.register(Strings.CMD_FILE_RENAME, Commands.FILE_RENAME, handleFileRename);
CommandManager.register(Strings.CMD_CLOSE_WINDOW, Commands.FILE_CLOSE_WINDOW, handleFileCloseWindow);
CommandManager.register(Strings.CMD_QUIT, Commands.FILE_QUIT, handleFileQuit);
CommandManager.register(Strings.CMD_REFRESH_WINDOW, Commands.DEBUG_REFRESH_WINDOW, handleFileReload);
CommandManager.register(Strings.CMD_ABORT_QUIT, Commands.APP_ABORT_QUIT, _handleAbortQuit);

CommandManager.register(Strings.CMD_NEXT_DOC, Commands.NAVIGATE_NEXT_DOC, handleGoNextDoc);
CommandManager.register(Strings.CMD_PREV_DOC, Commands.NAVIGATE_PREV_DOC, handleGoPrevDoc);
CommandManager.register(Strings.CMD_ABORT_QUIT, Commands.APP_ABORT_QUIT, _handleAbortQuit);
CommandManager.register(Strings.CMD_SHOW_IN_TREE, Commands.NAVIGATE_SHOW_IN_FILE_TREE, handleShowInTree);

// Listen for changes that require updating the editor titlebar
$(DocumentManager).on("dirtyFlagChange", handleDirtyChange);
Expand Down
19 changes: 6 additions & 13 deletions src/document/DocumentManager.js
Expand Up @@ -80,6 +80,7 @@ define(function (require, exports, module) {
FileUtils = require("file/FileUtils"),
CommandManager = require("command/CommandManager"),
Async = require("utils/Async"),
CollectionUtils = require("utils/CollectionUtils"),
PerfUtils = require("utils/PerfUtils"),
Commands = require("command/Commands");

Expand Down Expand Up @@ -171,13 +172,9 @@ define(function (require, exports, module) {
function findInWorkingSet(fullPath, list) {
list = list || _workingSet;

var ret = -1;
var found = list.some(function findByPath(file, i) {
ret = i;
return file.fullPath === fullPath;
});

return (found ? ret : -1);
return CollectionUtils.indexOf(list, function (file, i) {
return file.fullPath === fullPath;
});
}

/**
Expand Down Expand Up @@ -1074,12 +1071,8 @@ define(function (require, exports, module) {
function notifyPathNameChanged(oldName, newName, isFolder) {
var i, path;

// Update currentDocument
if (_currentDocument) {
FileUtils.updateFileEntryPath(_currentDocument.file, oldName, newName);
}

// Update open documents
// Update open documents. This will update _currentDocument too, since
// the current document is always open.
var keysToDelete = [];
for (path in _openDocuments) {
if (_openDocuments.hasOwnProperty(path)) {
Expand Down
73 changes: 53 additions & 20 deletions src/editor/Editor.js
Expand Up @@ -443,14 +443,36 @@ define(function (require, exports, module) {
{line: endLine, ch: this.document.getLine(endLine).length});
};

/**
* Ensures that the lines that are actually hidden in the inline editor correspond to
* the desired visible range.
*/
Editor.prototype._updateHiddenLines = function () {
if (this._visibleRange) {
var cm = this._codeMirror,
self = this;
cm.operation(function () {
// TODO: could make this more efficient by only iterating across the min-max line
// range of the union of all changes
var i;
for (i = 0; i < cm.lineCount(); i++) {
if (i < self._visibleRange.startLine || i > self._visibleRange.endLine) {
self._hideLine(i);
} else {
// Double-check that the set of NON-hidden lines matches our range too
console.assert(!cm.getLineHandle(i).hidden);
}
}
});
}
};

Editor.prototype._applyChanges = function (changeList) {
var self = this;

// _visibleRange has already updated via its own Document listener. See if this change caused
// it to lose sync. If so, our whole view is stale - signal our owner to close us.
if (this._visibleRange) {
if (this._visibleRange.startLine === null || this._visibleRange.endLine === null) {
$(self).triggerHandler("lostContent");
$(this).triggerHandler("lostContent");
return;
}
}
Expand All @@ -474,21 +496,7 @@ define(function (require, exports, module) {
});

// The update above may have inserted new lines - must hide any that fall outside our range
if (self._visibleRange) {
cm.operation(function () {
// TODO: could make this more efficient by only iterating across the min-max line
// range of the union of all changes
var i;
for (i = 0; i < cm.lineCount(); i++) {
if (i < self._visibleRange.startLine || i > self._visibleRange.endLine) {
self._hideLine(i);
} else {
// Double-check that the set of NON-hidden lines matches our range too
console.assert(!cm.getLineHandle(i).hidden);
}
}
});
}
this._updateHiddenLines();
};

/**
Expand Down Expand Up @@ -519,6 +527,10 @@ define(function (require, exports, module) {
this._duringSync = true;
this.document._masterEditor._applyChanges(changeList);
this._duringSync = false;

// Update which lines are hidden inside our editor, since we're not going to go through
// _applyChanges() in our own editor.
this._updateHiddenLines();
}
// Else, Master editor:
// we're the ground truth; nothing else to do, since Document listens directly to us
Expand Down Expand Up @@ -653,10 +665,31 @@ define(function (require, exports, module) {
/**
* Gets the current cursor position within the editor. If there is a selection, returns whichever
* end of the range the cursor lies at.
* @param {boolean} expandTabs If true, return the actual visual column number instead of the character offset in
* the "ch" property.
* @return !{line:number, ch:number}
*/
Editor.prototype.getCursorPos = function () {
return this._codeMirror.getCursor();
Editor.prototype.getCursorPos = function (expandTabs) {
var cursor = this._codeMirror.getCursor();

if (expandTabs) {
var line = this._codeMirror.getRange({line: cursor.line, ch: 0}, cursor),
tabSize = Editor.getTabSize(),
column = 0,
i;

for (i = 0; i < line.length; i++) {
if (line[i] === '\t') {
column += (tabSize - (column % tabSize));
} else {
column++;
}
}

cursor.ch = column;
}

return cursor;
};

/**
Expand Down
25 changes: 25 additions & 0 deletions src/editor/EditorCommandHandlers.js
Expand Up @@ -159,6 +159,30 @@ define(function (require, exports, module) {
var selectedText = doc.getRange(sel.start, sel.end) + delimiter;
doc.replaceRange(selectedText, sel.start);
}

/**
* Deletes the current line if there is no selection or the lines for the selection
* (removing the end of line too)
*/
function deleteCurrentLines(editor) {
editor = editor || EditorManager.getFocusedEditor();
if (!editor) {
return;
}

var from, to, sel, doc;

doc = editor._codeMirror;
sel = doc.getCursor(true);
from = {line: sel.line, ch: 0};
sel = doc.getCursor(false);
to = {line: sel.line + 1, ch: 0};
if (doc.lineCount() === to.line && from.line > 0) {
from.line -= 1;
from.ch = doc.getLine(from.line).length;
}
doc.replaceRange("", from, to);
}

/**
* Moves the selected text, or current line if no selection. The cursor/selection
Expand Down Expand Up @@ -278,6 +302,7 @@ define(function (require, exports, module) {
CommandManager.register(Strings.CMD_UNINDENT, Commands.EDIT_UNINDENT, unidentText);
CommandManager.register(Strings.CMD_COMMENT, Commands.EDIT_LINE_COMMENT, lineComment);
CommandManager.register(Strings.CMD_DUPLICATE, Commands.EDIT_DUPLICATE, duplicateText);
CommandManager.register(Strings.CMD_DELETE_LINES, Commands.EDIT_DELETE_LINES, deleteCurrentLines);
CommandManager.register(Strings.CMD_LINE_UP, Commands.EDIT_LINE_UP, moveLineUp);
CommandManager.register(Strings.CMD_LINE_DOWN, Commands.EDIT_LINE_DOWN, moveLineDown);
CommandManager.register(Strings.CMD_USE_TAB_CHARS, Commands.TOGGLE_USE_TAB_CHARS, toggleUseTabChars)
Expand Down

0 comments on commit 9180c43

Please sign in to comment.