Skip to content

Commit 0330e60

Browse files
author
Joseph Atkins-Turkish
committed
Fuzzyprompt subsections!
1 parent d8bbb30 commit 0330e60

File tree

7 files changed

+228
-117
lines changed

7 files changed

+228
-117
lines changed

ide/static/ide/css/ide.css

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,28 @@ span.cm-autofilled-end {
11361136
text-align: left;
11371137
}
11381138

1139+
.fuzzy-subheader {
1140+
/*background-color: #222;*/
1141+
font-weight: bold;
1142+
color: #555;
1143+
font-variant: small-caps;
1144+
margin-left: 1em;
1145+
1146+
}
1147+
.fuzzy-subheader::before {
1148+
/*content: '-- ';*/
1149+
}
1150+
1151+
.fuzzy-hint {
1152+
opacity: 0.5;
1153+
}
1154+
.fuzzy-hint::before {
1155+
content: ' <';
1156+
}
1157+
.fuzzy-hint::after {
1158+
content: '>';
1159+
}
1160+
11391161
#fuzzy-results > div {
11401162

11411163
line-height: 28px;

ide/static/ide/js/compile.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,9 @@ CloudPebble.Compile = (function() {
179179
commands[gettext("Show Phone Logs")] = function() { show_app_logs(ConnectionType.Phone); };
180180
commands[gettext("Show Emulator Logs")] = function() { show_app_logs(ConnectionType.Qemu); };
181181
commands[gettext("Show Last Build Log")] = function() {show_build_log(mLastBuild.id)};
182-
commands[gettext("Compilation")] = function() { show_compile_pane();};
183182
commands[gettext("Clear App Logs")] = function() { show_clear_logs_prompt(); };
184183
commands[gettext("Take Screenshot")] = function() { take_screenshot(); };
185-
CloudPebble.FuzzyPrompt.AddCommands(commands);
184+
CloudPebble.FuzzyPrompt.AddCommands(gettext('Actions'), commands);
186185

187186
SharedPebble.on('app_log', handle_app_log);
188187
SharedPebble.on('phone_log', handle_phone_log);

ide/static/ide/js/dependencies.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -609,9 +609,6 @@ CloudPebble.Dependencies = (function() {
609609
show_dependencies_pane();
610610
},
611611
Init: function() {
612-
var commands = {};
613-
commands[gettext("Dependencies")] = CloudPebble.Dependencies.Show;
614-
CloudPebble.FuzzyPrompt.AddCommands(commands);
615612
dependencies_template = $('#dependencies-pane-template').remove().removeClass('hide');
616613
alerts.init(dependencies_template);
617614

ide/static/ide/js/editor.js

Lines changed: 61 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CloudPebble.Editor = (function() {
44
var unsaved_files = 0;
55
var is_fullscreen = false;
66
var resume_fullscreen = false;
7+
var current_editor = null;
78

89
var add_source_file = function(file) {
910
CloudPebble.Sidebar.AddSourceFile(file, function() {
@@ -214,12 +215,8 @@ CloudPebble.Editor = (function() {
214215
return CodeMirror.Pass;
215216
};
216217
}
217-
settings.extraKeys['Cmd-/'] = function toggleComment(cm) {
218-
CodeMirror.commands.toggleComment(cm);
219-
};
220-
settings.extraKeys['Ctrl-/'] = function toggleComment(cm) {
221-
CodeMirror.commands.toggleComment(cm);
222-
};
218+
settings.extraKeys['Ctrl-/'] = 'toggleComment';
219+
settings.extraKeys['Cmd-/'] = 'toggleComment';
223220

224221
settings.gutters = ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'];
225222
if(file_kind_in(['js', 'json'])) {
@@ -243,6 +240,7 @@ CloudPebble.Editor = (function() {
243240
code_mirror.on('shown', function() {
244241
is_autocompleting = true;
245242
});
243+
current_editor = code_mirror;
246244

247245
// The browser should probably do this without our help. Sometimes Safari doesn't.
248246
$(document).click(function(e) {
@@ -580,16 +578,12 @@ CloudPebble.Editor = (function() {
580578
},
581579
pattern)
582580
};
581+
code_mirror.show_rename_prompt = show_rename_prompt;
583582

584583
var ib_pane = $('#ui-editor-pane-template').clone().removeClass('hide').appendTo(pane).hide();
585584
var ib_editor = new IB(ib_pane.find('.ui-canvas'), ib_pane.find('#ui-properties'), ib_pane.find('#ui-toolkit'), ib_pane.find('#ui-layer-list > div'));
586585
var ib_showing = false;
587586

588-
CloudPebble.GlobalShortcuts.SetShortcutHandlers({
589-
save: function() {
590-
save().catch(alert);
591-
}
592-
});
593587

594588
function toggle_ib() {
595589
if(!ib_showing) {
@@ -765,13 +759,6 @@ CloudPebble.Editor = (function() {
765759
fullscreen(code_mirror, true);
766760
}
767761

768-
var commands = {};
769-
commands[gettext('Rename File')] = function() {
770-
// We need to use a timeout because the rename prompt will conflict with the old prompt
771-
setTimeout(show_rename_prompt, 0);
772-
};
773-
CloudPebble.FuzzyPrompt.ReplaceCommands(commands);
774-
775762
// Tell Google
776763
ga('send', 'event', 'file', 'open');
777764
return code_mirror;
@@ -823,14 +810,66 @@ CloudPebble.Editor = (function() {
823810
edit_source_file(item.file);
824811
}
825812
});
826-
var commands = {};
813+
var global_commands = {};
827814
if (CloudPebble.ProjectProperties.is_runnable) {
828-
commands[gettext('Run')] = run;
815+
global_commands[gettext('Run')] = run;
829816
} else {
830-
commands[gettext('Build')] = run;
817+
global_commands[gettext('Build')] = run;
831818
}
819+
var local_commands = {};
820+
local_commands[gettext('Rename Source File')] = function() {
821+
// We need to defer because the rename prompt will conflict with the old prompt
822+
_.defer(function() {
823+
current_editor.show_rename_prompt();
824+
});
825+
};
826+
827+
function neaten_command_name(str) {
828+
var result = str.replace(/(\S)([A-Z])/g, '$1 $2').replace(/^./, function(str){ return str.toUpperCase(); });
829+
result = result.replace('Doc ', 'Document ');
830+
result = result.replace('Go ', 'Go To ');
831+
result = result.replace('Del ', 'Delete ');
832+
return result;
833+
}
834+
835+
var codemirror_commands = [
836+
{command: 'indentAuto', refocus: true},
837+
{command: 'toggleComment', hint: 'Cmd-/ or Ctrl-/', refocus: true},
838+
'find', 'replace', 'indentMore', 'indentLess'
839+
];
840+
841+
_.each(codemirror_commands, function(entry) {
842+
var command = !!entry.command ? entry.command : entry;
843+
var name = (!!entry.name ? entry.name : neaten_command_name(command));
844+
local_commands[name] = function() {
845+
current_editor.execCommand(command);
846+
if (!!entry.refocus) current_editor.focus();
847+
};
848+
local_commands[name].hint = !!entry.hint ? entry.hint : CloudPebble.GlobalShortcuts.GetShortcutForCommand(command);
849+
});
850+
851+
// local_commands[gettext('Auto Indent')] = function() {
852+
// current_editor.execCommand('indentAuto');
853+
// current_editor.focus();
854+
// };
855+
// local_commands[gettext('Auto Indent')].hint = CloudPebble.GlobalShortcuts.GetShortcutForCommand('indentAuto');
856+
// local_commands[gettext('Find')] = function() {
857+
// current_editor.execCommand('find');
858+
// };
859+
// local_commands[gettext('Find')].hint = CloudPebble.GlobalShortcuts.GetShortcutForCommand('find');
860+
861+
862+
CloudPebble.FuzzyPrompt.AddCommands(gettext('File'), local_commands, function() {
863+
return (!!current_editor);
864+
});
865+
866+
CloudPebble.GlobalShortcuts.SetShortcutHandlers({
867+
save: function() {
868+
save().catch(alert);
869+
}
870+
});
832871

833-
CloudPebble.FuzzyPrompt.AddCommands(commands);
872+
CloudPebble.FuzzyPrompt.AddCommands(gettext('Actions'), global_commands);
834873

835874
}
836875

0 commit comments

Comments
 (0)