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

Commit

Permalink
Merge remote-tracking branch 'origin/master' into pflynn/find-unit-tests
Browse files Browse the repository at this point in the history
* origin/master:
  Code cleanup.
  Add no-focus to jslint and search results
  Remove empty style rule
  More improvements in Find.
  Add .no-focus style and implementation.
  Refine find logic with pre-selected query string.
  • Loading branch information
peterflynn committed Dec 8, 2012
2 parents 1abb001 + 2554f28 commit 4c9bb22
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 19 deletions.
7 changes: 7 additions & 0 deletions src/brackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,13 @@ define(function (require, exports, module) {
}
});

// The .no-focus style is added to clickable elements that should
// not steal focus. Calling preventDefault() on mousedown prevents
// focus from going to the click target.
$("html").on("mousedown", ".no-focus", function (e) {
e.preventDefault();
});

// Localize MainViewHTML and inject into <BODY> tag
var templateVars = $.extend({
ABOUT_ICON : brackets.config.about_icon,
Expand Down
6 changes: 3 additions & 3 deletions src/htmlContent/main-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
-->
<div class="content">
<!-- Toolbar containing menus, filename, and icons -->
<div id="main-toolbar" class="toolbar">
<div id="main-toolbar" class="toolbar no-focus">
<!-- Menu bar -->
<ul class="nav" data-dropdown="dropdown">
</ul>
Expand All @@ -94,14 +94,14 @@
</div>
</div>

<div id="jslint-results" class="bottom-panel vert-resizable top-resizer">
<div id="jslint-results" class="bottom-panel vert-resizable top-resizer no-focus">
<div class="toolbar simple-toolbar-layout">
<div class="title">{{JSLINT_ERRORS}}</div>
</div>
<div class="table-container resizable-content"></div>
</div>

<div id="search-results" class="bottom-panel vert-resizable top-resizer">
<div id="search-results" class="bottom-panel vert-resizable top-resizer no-focus">
<div class="toolbar simple-toolbar-layout">
<div class="title">{{SEARCH_RESULTS}}</div>
<div class="title" id="search-result-summary"></div>
Expand Down
41 changes: 26 additions & 15 deletions src/search/FindReplace.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ define(function (require, exports, module) {
cm.setSelection(cursor.from(), cursor.to());
state.posFrom = cursor.from();
state.posTo = cursor.to();
state.findNextCalled = true;
});
return found;
}
Expand Down Expand Up @@ -142,13 +143,17 @@ define(function (require, exports, module) {
* If no search pending, opens the search dialog. If search is already open, moves to
* next/prev result (depending on 'rev')
*/
function doSearch(cm, rev) {
function doSearch(cm, rev, initialQuery) {
var state = getSearchState(cm);
if (state.query) {
return findNext(cm, rev);
}

var searchStartPos = cm.getCursor();
// Use the selection start as the searchStartPos. This way if you
// start with a pre-populated search and enter an additional character,
// it will extend the initial selection instead of jumping to the next
// occurrence.
var searchStartPos = cm.getCursor(true);

// Called each time the search query changes while being typed. Jumps to the first matching
// result, starting from the original cursor position
Expand Down Expand Up @@ -180,15 +185,26 @@ define(function (require, exports, module) {
}

dialog(cm, queryDialog, Strings.CMD_FIND, function (query) {
// If the dialog is closed and the query string is not empty,
// make sure we have called findFirst at least once. This way
// if the Find dialog is opened with pre-populated text, pressing
// enter will find the next occurance of the text and store
// the query for subsequent "Find Next" commands.
if (query && !state.query) {
if (!state.findNextCalled) {
// If findNextCalled is false, this means the user has *not*
// entered any search text *or* pressed Cmd-G/F3 to find the
// next occurrence. In this case we want to start searching
// *after* the current selection so we find the next occurrence.
searchStartPos = cm.getCursor(false);
findFirst(query);
}
});

// Prepopulate the search field with the current selection, if any.
if (initialQuery !== undefined) {
getDialogTextField()
.attr("value", initialQuery)
.get(0).select();
findFirst(initialQuery);
// Clear the "findNextCalled" flag here so we have a clean start
state.findNextCalled = false;
}

getDialogTextField().on("input", function () {
findFirst(getDialogTextField().attr("value"));
});
Expand Down Expand Up @@ -257,7 +273,7 @@ define(function (require, exports, module) {
});
});

// Prepopulate the replace field with the current selection, if any
// Prepopulate the replace field with the current selection, if any.
getDialogTextField()
.attr("value", cm.getSelection())
.get(0).select();
Expand All @@ -270,12 +286,7 @@ define(function (require, exports, module) {

// Bring up CodeMirror's existing search bar UI
clearSearch(codeMirror);
doSearch(codeMirror);

// Prepopulate the search field with the current selection, if any
getDialogTextField()
.attr("value", codeMirror.getSelection())
.get(0).select();
doSearch(codeMirror, false, codeMirror.getSelection());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/widgets/StatusBar.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div id="status-bar" class="statusbar">
<div id="status-bar" class="statusbar no-focus">
<div id="status-info" class="info" >
<div id="status-cursor"></div>
</div>
Expand Down

0 comments on commit 4c9bb22

Please sign in to comment.