OS X, Sublime Text 3
I can double click a word and use CMD + D to select the next instance of the word.
However if I want to replace this 30 times I need to CMD + D 30 times.
Is there a way to have it select all that it finds?
OpeningScene* OpeningScene::pinstance = 0;
OpeningScene* OpeningScene::Instance()
{
if (pinstance == 0)
{
pinstance = new OpeningScene;
pinstance->initInstance();
}
return pinstance;
}
OpeningScene::OpeningScene() { }
In the above, replacing OpeningScene I'd need to CMD + D 6 times after double clicking the first instance.
I guess I could do a Find/Replace using the dialog but is there a keyboard way of doing this?
Yes. Put your cursor over the word and type:
Ctrl+Cmd+G
This should do a quick find all on your current word.
Related
Let's have contenteditable div. Browser itself manage undo on it.
But when additional content changes (or touching selection ranges) are made from script (in addition to user action) then it stops behave as user expected.
In other words when user hit Ctrl+Z then div content is not reverted to previous state.
See following simplified artificial example:
https://codepen.io/farin/pen/WNEMVEB
const editor = document.getElementById("editor")
editor.addEventListener("keydown", ev => {
if (ev.key === 'a') {
const sel = window.getSelection()
const range = window.getSelection().getRangeAt(0)
const node = range.startContainer;
const value = node.nodeValue
node.nodeValue = value + 'aa'
range.setStart(node, value.length + 2)
range.setEnd(node, value.length + 2)
ev.preventDefault()
}
})
All written 'a' letters are doubled.
Undo is ok as long as there is no 'a' typed.
When user typed 'a' (appended to text as double 'aa') and hits Ctrl+Z, then he expects both 'a' will be removed and cursor moves back to original position.
Instead only one 'a' is reverted on undo and second one added by script remain.
If event is also prevented by preventDefault() (which is not needed in this example, but in my real world example i can hardly avoid it) then all is worse.
Because undo reverts previous user action.
I could images that whole undo/redo stuff will be managed by script, but it means implementation of whole undo/redo logic. That's too complicated, possible fragile and with possible many glitches.
Instead I would like tell browser something like that there is atomic change which should be reverted by one user undo. Is this possible?
You can store the "revisions" in an array, then push the innerHTML of the div to it whenever you programmatically change the innerHTML of it.
Then, you can set the innerHTML of the div to the last item in the revisions array whenever the user uses the Ctrl + Z shortcut.
const previousRevisions = []
function saveState() {
previousRevisions.push(editor.innerHTML)
}
function undoEdit() {
if (previousRevisions.length > 0) {
editor.innerHTML = previousRevisions.pop();
}
}
const editor = document.getElementById("editor")
editor.addEventListener("keydown", ev => {
if (ev.key === 'a') {
saveState()
const sel = window.getSelection()
const range = window.getSelection().getRangeAt(0)
const node = range.startContainer;
const value = node.nodeValue
node.nodeValue = value + 'a'
range.setStart(node, value.length + 1)
range.setEnd(node, value.length + 1)
} else if (ev.ctrlKey && ev.key == 'z') {
undoEdit()
}
})
#editor{width:600px;min-height:250px;border:1px solid black;font-size:24px;margin:0 auto;padding:10px;font-family:monospace;word-break:break-all}
<div id="editor" contenteditable="true">type here </div>
The benefit of this solution is that it will not conflict with the browser's native Ctrl + Z shortcut behavior.
Make the parent a div (if it isn't) and make it so it adds spans inside of it every time the user taps a so the new span and set it's id to span-keyword will have aa as the value / text. Then check if the users cursor is at the beginning of it and check if there is no other text in-front of it and the user did no other action in it. If there is no text and no other actions happened do this:
document.getElementById('span-keyword').remove();
I am having an issue where a field is stored in our database as '##ABC' with no space between the number and letters. The number can be anything from 1-100 and the letters can be any combination, so no consistency of beginning letter or numeric length.
I am trying to find a way to insert a space between the number and letters.
For example, '1DRM' would transform to '1 DRM'
'35PLT' would transform to '35 PLT'
Does anyone know of a way to accomplish this?
You can use regular expressions like the one below (assuming your pattern is digits-characters)
= System.Text.RegularExpressions.Regex.Replace( Fields!txt.Value, "(\d)(\D)", "$1 $2")
Unfortunately, there's no built in function to do this.
Fortunately, Visual Studio lets you create functions to help with things like this.
You can add Visual BASIC custom code by going to the Report Properties and going to the Custom Code tab.
You would just need to write some code to go through some text input character by character. If it finds a number and a letter in the next character, add a space.
Here's what I wrote in a few minutes that seems to work:
Function SpaceNumberLetter(ByVal Text1 AS String) AS String
DIM F AS INTEGER
IF LEN(Text1) < 2 THEN GOTO EndFunction
F = 1
CheckCharacter:
IF ASC(MID(Text1, F, 1)) >= 48 AND ASC(MID(Text1, F, 1)) <=57 AND ASC(MID(Text1, F + 1, 1)) >= 65 AND ASC(MID(Text1, F + 1, 1)) <=90 THEN Text1 = LEFT(Text1, F) + " " + MID(Text1, F+1, LEN(Text1))
F = F + 1
IF F < LEN(Text1) THEN GOTO CheckCharacter
EndFunction:
SpaceNumberLetter = Text1
End Function
Then you call the function from your text box expression:
=CODE.SpaceNumberLetter("56EF78GH12AB34CD")
Result:
I used text to test but you'd use your field.
I'm looking for a keyboard shortcut in PhpStorm to allow me to select or extend a selection of multiple contiguous lines. I know about Ctrl + Shift + W to select the parent/containing node, but how can I select the next sibling node?
Say for example I have:
foreach($somevar as $name=>$value) {
$temp1 = $name . "_1";
$temp2 = $name . "_2";
echo $value;
}
With Ctrl + Shift + W I can very easily extend the selection to include the whole of the line with $temp1 on it, but if I use Ctrl + Shift + W to extend beyond this, I'll get everything within the foreach.
If I have the line with $temp1 already selected, how can I extend the selection to include line $temp2 without also selecting echo $value?
We know that there is a way to reformat and rearrange codes via Ctrl+ alt + l in phpStorm and it works fine.
But this ability can not reformat codes in a simple String(codes that are surrounded by single or double quotes).
For example this code is to run a select Query on DB :
$getPro = $db->Query("select products.`product_id`,products.`pro_title`, products.`pro_quantity`,products.`new_price`,products.`addedPrice`,products.`discount`, product_pics.`pic_name`
from `products` left join `product_pics` on `product_pics`.`product_id` = products.`product_id`
where products.`product_id`=:p_id limit 1", array (':p_id' => $p_id));
and i want to reformat this code to bellow one on pressing Ctrl+ alt + l or Any other way:
$getPro = $db->Query("SELECT
products.`product_id`,
products.`pro_title`,
products.`pro_quantity`,
products.`new_price`,
products.`addedPrice`,
products.`discount`,
product_pics.`pic_name`
FROM `products`
LEFT JOIN `product_pics` ON `product_pics`.`product_id` = products.`product_id`
WHERE products.`product_id` = :p_id
LIMIT 1
", array (':p_id' => $p_id));
Of course I realized that we can do this via copy SQL string in phpStorm MySQL Console (Ctrl+shift+f10) and then use Ctrl+ alt + l shortcut.
What is the solution in your opinion?
Edit:
according to LazyOne comment, this is a screenshot of my code when pressing Alt+Enter . But there is no Edit MySQL Fragment option.
I have a file text more than 1 000 000 lines that begins by the character C and other one by M
Example:
C9203007870000000000000006339912610971240095400111200469300000 16122011AMI 00000100010000315 080
C9203007870000000000000006339912610971240095400111200469300000 09122011B 590001000100000270016092100
M920300787000000000000000633991261097124009540011120046930000031122011JVJF004 10 N
M920300787000000000000000633991261097124009540011120046930000009122011DEQP003 10 N
M920300787000000000000000633991261097124009540011120046930000012122011ACQK001 10Z N
C9203007870000000000000006339912610971240095400111200469300000 24122011AMI 00000100010000315 080
C9203007870000000000000006339912610971240095400111200469300000 24122011AMI 00000100010000315 080
I want to put in my array only the lines who begins with the character M
How I can add in my split: var pattern:RegExp = /^M/;
var mFileReference:FileReference;
var mArray:Array = new Array();
function onFileLoaded(event:Event):void
{
mFileReference = event.target as FileReference;
data = mFileReference["data"];
mArray = (data.toString()).split("\n");
}
I don’t want to pass by the loop ‘for’ its take a lot of time and resources
I want to add /^M/ to my split is it possible?
for each (var s:String in mArray)
{
if (pattern.test(s)) {
values.push(s);
}
}
Thanks everybody.
Try this regular expression:
/^M.*/gm
This should match all lines that begin with M and nothing else.
It uses the g flag to match all cases of the expression in the string, and it uses m for multiline mode, so ^ and $ will match the beginning/end of lines instead of the beginning/end of the string.
You can get get your array like this:
mArray = data.toString().match(/^M.*/gm);