How to show the find and replace panel with a pre-populated search string? - sublimetext3

I know that it is possible to show the Sublime Text "Find and Replace" panel using the show_panel command (either via a keybinding or a plugin), and control which arguments are enabled/disabled.
Example run from Sublime Console panel:
window.run_command('show_panel', { 'panel': 'replace', 'regex': True, 'case_sensitive': False, 'whole_word': False, 'in_selection': False, 'wrap': True, 'highlight': True, 'preserve_case': True })
What I would like to know, is: is there a way to pre-populate the Find What: and Replace With: values?
I found this forum post but it has no reply, and the unofficial documentation is of no help in this case.
I have tried:
'find_what': 'string'
'replace_with': 'string'
'find_history': 'string'
'replace_history': 'string'
'find_history': ['string']
'replace_history': ['string']
'find': 'string'
'replace': 'string'
EDIT: I have also tried:
characters
find_characters
look_for
search_for
find_regex
find_string
search_string
replacement
search_characters
and none of the above makes any difference - the panel is always pre-populated with the previous search and replace values, not what I pass in.
I am aware of the commands slurp_find_string and slurp_replace_string, which will take the current selection and update the Find What / Replace With values respectively, but I would like a way to do it without having to mess around with selections first - I just want to pass the values as arguments directly to the show_panel command.
Does anyone know what parameters/arguments can be used to control this?

You can run an insert command on the window just after you've run the show_panel command.
import sublime_plugin
class ShowPanelPrefilledCommand(sublime_plugin.WindowCommand):
def run(self, interactive=True):
self.window.run_command('show_panel', {
'panel': 'find_in_files',
'where': '<open folders>',
'whole_word': False,
'case_sensitive': False,
'preserve_case': False,
'regex': False,
'use_buffer': False,
'show_context': False,
})
self.window.run_command('insert', {'characters': 'hello'})
if not interactive:
self.window.run_command('find_all', {'close_panel': True})

I wanted to do the same thing for a key binding command that opens a Package Tool and uses the Find Search window. I ended up with something easy to customize and use for any command that just uses another key binding.
After I run my Package Tool, I just use this key binding to insert the text (which is a complicated regex in my case). For me on OSX, it's intuitively remembered as (insert 1) CMD+i, CMD+1
Open Sublime Text / Preferences / Key Bindings
Add this to the User - Default (OS).sublime-keymap
{ "keys": ["super+i", "super+1"], "command": "insert", "args": { "characters": "my-custom-insert-text1" } },
{ "keys": ["super+i", "super+2"], "command": "insert", "args": { "characters": "my-custom-insert-text2" } },
// etc..

This feature was added in Sublime Text build 4123 on 6 December 2021.
The show_panel command for the find and find in files panels can now take "pattern" and "replace_pattern" arguments.

Related

Changing anyMatch default for Filter.JS in ExtJS for MultiSelect search

I have a multiselect bound to a store in which I implemented use of anyMatch: true to allow for True to allow any match - no regex start/end line anchors will be added (as per the comment in Filter.js). My problem is that I need to implement this as per the answer to multiselect-search-whole-string, in particular the solution provided in this fiddle https://fiddle.sencha.com/#fiddle/jf5
What I want to do is just set anyMatch: true, regardless, so I set it in Filter.js, but this has no effect on use of it. I searched the entire codebase for other instances of anyMatch: false and the only other one is in ext-all-debug.js. Why isn't setting these values having any effect? I don't see where else this default value could be set?
EDIT 1
I tried a different override, and while it is not exhibiting the right behavior, it is actually doing something this time. I figured that since the chunk of code that does work when embedded in the search attribute within the MultiSelector control was pretty much what was found in the MultiSelectorSearch's search method, that this was what I needed to focus on for the override. Any suggestions on tweaking this would be most welcome:
Ext.define('Ext.overrides.view.MultiSelectorSearch', {
override: 'Ext.view.MultiSelectorSearch',
search: function (text, me) {
var filter = me.searchFilter,
filters = me.getSearchStore().getFilters();
if (text) {
filters.beginUpdate();
if (filter) {
filter.setValue(text);
} else {
me.searchFilter = filter = new Ext.util.Filter({
id: 'search',
property: me.field,
value: text,
anyMatch: true
});
}
filters.add(filter);
filters.endUpdate();
} else if (filter) {
filters.remove(filter);
}
}
});
EDIT 2
Got it! The key was that originally, since this code was embedded in a singleton, I could reference the method by passing me from the calling form.panel. This did not work globally as an override, and required me to define the method as
search: function (text) {
var me = this,
I hope this helps someone out there!
Changing in ext-all-debug.js is not safe, when you do a production build this file will not get included.
Best way is to override the Filter class, here is how you can do it.
Ext.define('Ext.overrides.util.Filter', {
override: 'Ext.util.Filter',
anyMatch: true
});
And import this class in Application.js
Ext.require([
'Ext.overrides.util.Filter'
]);

browserify without sourcemaps

I'm using Browserify programmatically, through node, like so:
var options = {
debug: true,
cache: {},
packageCache: {},
fullPaths: true,
noParse: []
};
var b = browserify( 'index.js', options );
b.on('data', customFunction);
b.bundle();
My customFunction doesn't modify the data anyhow, just reads it.
It runs a regex on the first line, to detect the file name of the code that comes on the following lines.
The thing is, when i set options.debug to false, to get rid of the sourcemaps, the customFunction behaves in a very different way (the regex doesn't get half the file names) and i can't seem to figure out the pattern for that difference. I assume that turning debug to false, does more than turning off the sourcemaps.
I just want to turn off the sourcemaps on browserify, with no other side-effects, is this possible?
You could try to extract the source maps with a separate tool like exorcist https://github.com/thlorenz/exorcist

i18next: fallback to [same language + different namespace] instead of [different language + same namespace]

This is about using i18next in a node.js backend.
This is the initialization:
i18next.init({
lng: 'de',
fallbackLng: ['de'],
ns: {
namespaces: ['formal', 'informal'],
defaultNs: 'formal'
},
fallbackToDefaultNS: true,
resStore: {
de: resourcesDE,
en: resourcesEN
}
});
where resourcesDE is an object with structure { formal: { }, informal: { }} and resourcesEN has the same structure but only 'formal', no 'informal' (but I have this problem even if there is 'informal' in resourcesEN).
Now, what I want to have is:
If I request the translation of 'informal:myKey' for English that the search route (== fallback) is:
(en)'informal:myKey' > (en)'myKey' > (de)'informal:myKey' > (de)'myKey'
or
(en)'informal:myKey' > (en)'myKey' > (de)'myKey'
but what actually happens is:
(en)'informal:myKey' > (de)'informal:myKey' > (de)'myKey'
meaning that the language changes before even trying to get a text of the same language from a different (the default) namespace.
How can I achieve this or something along those lines. I've also tried using a context instead of namespaces for these alternatives, but that seemed to behave the same. I'm glad to be proven wrong though.
The solution that worked out for me, in the end:
Instead of namespaces, I use special language flavors: 'de-INFORMAL' and 'en-INFORMAL'. If no label is found under 'en-INFORMAL', the lookup falls back to 'en', first and out of the box. If fallbackLng is set to 'de' it will fallback to that if the label in not found in 'en', either.

Using shifted function keys in XKB keyboard layout

I'm working on a Khmer keyboard layout and I've run into a problem at the last step of the project.
Khmer has 33 consonant characters, 24 vowel diacritic characters, and another 14 independent vowels characters. On top of this, I have included each character's corresponding International Phonetic Alphabet symbol(s) in my layout at the ALT and SHIFT-ALT levels, so very quickly I'm running out of space.
To alleviate this I was planning to map the 24 vowel diacritics to F1 - F12 and SHIFT F1 - F12 (with the corresponding IPA characters at the ALT and SHIFT/ALT levels) but the SHIFT + FN, ALT + FN and SHIFT/ALT + FN combinations don't register. I've tried the combinations in different text editors, browsers, and the terminal but none work. It seems to be a system wide problem.
I am running Ubuntu 10.04.
Here's the section in my layout that pertains to the FN keys:
key <FK01> { [ 0x10017b6, 0x10017c2, voidsymbol, voidsymbol ] };
key <FK02> { [ 0x10017b7, 0x10017c3, voidsymbol, voidsymbol ] };
key <FK03> { [ 0x10017b8, 0x10017c4, voidsymbol, voidsymbol ] };
key <FK04> { [ 0x10017b9, 0x10017c5, voidsymbol, voidsymbol ] };
key <FK05> { [ 0x10017ba, voidsymbol, voidsymbol, voidsymbol ] };
key <FK06> { [ 0x10017bb, voidsymbol, voidsymbol, voidsymbol ] };
key <FK07> { [ 0x10017bc, voidsymbol, voidsymbol, voidsymbol ] };
key <FK08> { [ 0x10017bd, voidsymbol, voidsymbol, voidsymbol ] };
key <FK09> { [ 0x10017be, voidsymbol, voidsymbol, voidsymbol ] };
key <FK10> { [ 0x10017bf, voidsymbol, voidsymbol, voidsymbol ] };
key <FK11> { [ 0x10017c0, voidsymbol, voidsymbol, voidsymbol ] };
key <FK12> { [ 0x10017c1, voidsymbol, voidsymbol, voidsymbol ] };
As you can see I've only filled out SHIFT F1 - F4 so far, I'll do the rest when or if I get those keys working.
Hopefully some of you can point me in the right direction.
I don't know why the combinations don't register, but as an alternative solution think perhaps of utilising more levels per key, for example using level5 (by including one of the symbol definitions to map some key to the level5 modifier) and defining the key mapping using an eight-level type, such as EIGHT_LEVEL or EIGHT_LEVEL_ALPHABETIC.
My guess is that the default fallback "type" of your FN keys are not including enough keys. E.g, if you have
key <FK01> { type = "TWO_LEVEL", [FirstKey,SecondKey,ThirdKey,...]}
then only FirstKey and SecondKey can be generated. If you have
key <FK01> { type = "CTRL+ALT", [FirstKey,SecondKey,ThirdKey,...]}
then the alt and ctrl and ctrl+alt levels should be recognized, giving you 5 levels, 4 of which you might want to change (you probably don't want to change the ctrl level). Do keep in mind that you probably want to be able to use CTRL+ALT+FN to switch out of X to a terminal in case of emergency, or to at least have some key bound to XF86Switch_VT_1 somewhere in your layout.
You might also want to differentiate between Alt and AltGr, the latter named ISO_Level3_Shift in xkb.
If you want to create and use a ISO_Level5_Switch button somewhere on your keyboard you can use the type "EIGHT_LEVEL" or similar to recognize all combinations of (no modifier),level3 and level5 for a total of 8 levels.
(I have Alt_L bound to my left Alt button, ISO_Level3_Shift bound to my right Alt button, and ISO_Level5_Shift bound to my right "windows" button)
Your keymap will probably need to import some of the key types from elsewhere. In the xkb_types section of your .xkb file, add the line
augment "level5"
to include "LEVEL_EIGHT" and other similar types into your layout.
The files in /usr/share/X11/xkb/types/ should show you which types are available on your system, and which file you need to add to your .xkb file with an augment line to use the type. (They might be in a different directory on your system, since I use Gentoo; type locate level5 in a terminal to find where the directory is for you.) If you feel the need, you can also construct your own type directly into the xkb_types section of your .xkb file, after the augment lines. Look in the files in /usr/share/X11/xkb/types/ to see the syntax of a type definition.
You'll also want to add the line to your xkb_compatibility section, not just the xkb_types section; xkb_types provides the types, xkb_compatibility defines modifier key behavior, so while an augment "level5" in xkb_types will give you access to types like "EIGHT_LEVEL", an augment "level5" in xkb_compatibility will make a key bound to ISO_Level5_Shift actually act as a modifier.
Just to give you an idea, my own xkb_compatibility section looks like this:
xkb_compatibility "complete" {
// "pc" would only set Alt, need "pc98" for NumLock
include "pc98" // Numlock
augment "misc" // Alt,Meta,Super,Hyper ...
augment "ledscroll(group_lock)" // Set scroll lock on group switch
augment "xfree86" // Switch out to terminal
augment "caps" // Simple caps thing
augment "iso9995" // level3,groups
augment "level5" // level5
};
I'm not sure if all .xkb files include these sections or if it's just mine.
IIRC, there's often some GUI way to include level3, level5 and the likes when you set your layout rather than in the layout file itself, if that's more to your liking.
If you want to go deeper, I can recommend something like https://www.charvolant.org/doug/xkb/

How set class to input on error using jQuery-validation-engine

I'm using the jquery-validation-engine plugin and after validate I need to add a class to the inputs with the error promt to add for example a red border or something like that, is there a way using the plugin configuration to setup this?
I alsow use that same plugin.
Do you have the last verion off the plug-in ?
In the file: jquery.validationEngine.js
you will find almost at the bottom:
InvalidFields: [],
onFieldSuccess: false,
onFieldFailure: false,
onSuccess: false,
onFailure: false,
addSuccessCssClassToField: false,
addFailureCssClassToField: false,
These are the 'master' settings for the options you are looking for.
My current setup is like:
InvalidFields: [],
onFieldSuccess: true,
onFieldFailure: true,
onFormSuccess: false,
onFormFailure: false,
addSuccessCssClassToField: 'inputbox-success',
addFailureCssClassToField: 'inputbox-error',
And then the two css classes in youre css file ( 'inputbox-error' & 'inputbox-succes').
This works just fine over here..
Good Luck...
And if you have any more question about this plugin or other functions off it just ask .. :P
Greets,
Marco

Resources