PhpStorm keyboard shortcut to extend text selection over next line - phpstorm

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?

Related

How to undo changes made from script on contenteditable div

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();

Start a new line after exactly two words of a string in SSRS-2008

I have this string that is coming from the db and the words are separated by a space. the number of words can vary from a minimum of one to a maximum of six, so what i essentially want is to start a new line immediately after the second word.
For example the string "Natural Financial Services" needs to show as:expected result
in the report. i case if there is only one word then there should not be any line break, i have tried this Replace(Fields!CustodianNameTxt.Value," ",Vbcrlf) but this will cause each word of the string to appear in a separate line, like this:result with my current expression
Which is not what is expected, anyone please suggest if there is any solution to achieve this?
Thanks in advance.
Select report properties -> Code
Add this function (there might be better ways of achieving the same in VB, this is just one example):
Public Function splitline(byval line as string) as string
dim words() as string=line.split(" ") ' separate the lines into array of words
dim pos as integer ' to calculate the position for the breaks
dim newlines as string = line ' string for the line with added breaks
if words.length > 2 then ' there are 3 or more words add break after second word
pos=len(words(0)) + len(words(1)) + 1 ' this will be the position of the first break
newlines=newlines.remove(pos,1).insert(pos,VBCRLF) ' remove the space and add a break
end if
if words.length > 4 then ' there are 5 or more words add break after forth word
pos=len(words(0)) + len(words(1)) + len(words(2)) + len(words(3)) + 4 ' adding 4 because 2 spaces + cr + lf
newlines=newlines.remove(pos,1).insert(pos,VBCRLF) ' remove the space and add a break
end if
return newlines
End Function
The expression in the will then just be:
Code.splitline(Fields!CustodianNameTxt.Value)
One way it can be done is by splitting the string into an array of words and then rebuilding it with the added CRLF using choose function
In this example, the choose are inside an isnothing to cater for lines with less than six words:
=IIF(not isnothing(choose(1,split(Fields!CustodianNameTxt.Value," ")))," " + choose(1,split(Fields!CustodianNameTxt.Value," ")),"")
+IIF(not isnothing(choose(2,split(Fields!CustodianNameTxt.Value," ")))," " + choose(2,split(Fields!CustodianNameTxt.Value," ")) + Vbcrlf,"")
+IIF(not isnothing(choose(3,split(Fields!CustodianNameTxt.Value," ")))," " + choose(3,split(Fields!CustodianNameTxt.Value," ")),"")
+IIF(not isnothing(choose(4,split(Fields!CustodianNameTxt.Value," ")))," " + choose(4,split(Fields!CustodianNameTxt.Value," ")) + Vbcrlf,"")
+IIF(not isnothing(choose(5,split(Fields!CustodianNameTxt.Value," ")))," " + choose(5,split(Fields!CustodianNameTxt.Value," ")),"")
+IIF(not isnothing(choose(6,split(Fields!CustodianNameTxt.Value," ")))," " + choose(6,split(Fields!CustodianNameTxt.Value," ")),"")

Can't click cell in HTML table

I'm writing a script to login to an internal html site, click around to the appropriate place, click on a specific row in an HTML table, and click a submit button. I'm pretty much there, except I can't figure out how to click the correct row - or any row for that matter.
Here is the source of the table: HTML Source
Here is what I've tried so far after navigating to the page with the table of interest (with no results, but no errors):
Set mainTable = IE.Document.getElementByID("main").contentwindow.document
mainTable.getElementsByName("acq_scenario.acq_scenario_summary").Item(0).getElementsByTagName("tr").Item(0).getElementsByTagName("td").Item(3).focus
mainTable.getElementsByName("acq_scenario.acq_scenario_summary").Item(0).getElementsByTagName("tr").Item(0).getElementsByTagName("td").Item(3).click
The code below tries to change the attributes in the HTML table based on changes that I've observed when manually clicking on a cell, but these changes have no effect on the view of the table (the row should be highlighted when a cell within it is clicked) and still don't allow me to click the submit button, which requires a row to be selected:
currScenario = mainTable.getElementsByName("acq_scenario.acq_scenario_summary").Item(0).getElementsByTagName("tr").Item(1).getElementsByTagName("td").Item(2).realValue 'gets string value for "Current Scenario" field, which I've unsuccessfully tried to use to manually update the "selected" attribute in the table
mainTable.getElementsByName("acq_scenario.acq_scenario_summary").Item(0).setAttribute "selected", "ScenarioName=" & currScenario
mainTable.getElementsByName("acq_scenario.acq_scenario_summary").Item(0).getElementsByTagName("tr").Item(0).setAttribute "class", "Skin_Selection_Color"
mainTable.getElementsByName("acq_scenario.acq_scenario_summary").Item(0).getElementsByTagName("tr").Item(0).style.setAttribute "highlight", "true"
I am a little fuzzy on what you need, but I think that using css for the row highlight and a onClick for the cell selection..
"the row should be highlighted when a cell within it is clicked"
CSS:
#msg_table tr:hover{background-color:white; }
Javascript:
/* create HTML table in Javascript */
for (var j = 0; j < search_results_length; j++){
// get zebra striping
if (j % 2 == 0){
//even
zebra = "zebra_0";
}else{
//odd
zebra = "zebra_1";
}
...
myTable+="<tr class='" + zebra + "' onClick='collapse_section_switch(" + j + ")'>"
/* row click here */
myTable+="<td align='right' onClick='balance_stuff(\"search_results[j].customer_number\")'>" + search_results[j].customer_balance + "</td>"
/* cell click here */
...
}
Does this help at all?
I still don't understand why the .click() command wouldn't click on the cell, but it turns out the answer was to use .FireEvent("onmouseup").

How to multiply the font size in html? ActionScript 3 implemention

Please read the examples compare input and output. Defrent is in size=[Values]. How to replace it?
input:
"<font size='30'> Head </font><br></br> <font color='#b5fe01' size='50'>Progress:</font>"
and I want multiply all font sizes by 2 and replace it in original input.
output:
"<font size='60'> Head </font><br></br> <font color='#b5fe01' size='100'>Progress:</font>"
Thanks
AS3 regexp as requested:
var multiply:Function = function(matched:String, start:String, size:String, index:int, str:String):String
{
return start + (2 * int(size)).toString() + "'";
}
var match:RegExp = /(<font[^>]*size=')(\d+)'/gi;
var src:String = "<font size='30'> Head </font><br/> <font color='#b5fe01' size='50'>Progress:</font>";
var replaced:String = src.replace(match, multiply);
Explanation:
multiply - Takes "start" and "size" params. "start" is the previously matched part of font tag. This is required as we need to know we are in font tag, yet we only want to replace the size value. "size" is the actual size value.
RegExp - Captures as first group "<font" followed by any number of non-'>' characters, followed by "size='". Second group is the value of size. match is finished with "'" after size value, which is not captured. g stands for "global" and makes multiple-times matching on single string, i makes matching case-insensitive.
This is not a foolproof solution but I think it follows the basic idea and is easy to extend for more universal usage.
We should do this with a HTML/XML processor...
Using just pure perl:
#!/usr/bin/perl -i
while(<>){
s/(<font\s)(.*?)(>)/$1 . repsize($2) . $3 /ge;
print
}
sub repsize{my $atribs=shift;
return $atribs =~ s/(size=.)(\d+)/ $1 . $2*2/er;
}

Sublime Text and Multiple Selection with CMD + D

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.