insert double quotes around selected text in xcode - javascript

Is there a keystroke to add double quotes around a selection in xcode?
I have snippets #"<#string#>" (qt) and #"<#string#>"<#, #> (qtc)(for making a list in array I use keystroke qtc+enter word tab enter qt+enter...) that I use when I am typing, but I also could use some sort of a macro that I could highlight the word, tap a keystroke, and it would add #"" around it. It seems a little easier. Once you enter the first qtc then you just need qt enter to get the next one from the code popup.
Is there a macro that would put the quotes around the current word the cursor is on? I have seen something like this in TextMate.
This would be a little convenience that would be nice when I am adding a list of words to an array or something and putting the quotes around all the words.
Maybe a little javascript to put in a webpage that would loop though and put the quotes each word in a list would be useful. Or better yet an applescript or some sort of macro that could be used in xcode that would loop through words in a selection and add #"", around each word that could be triggered with a keystroke. Then you could just type a list and select it and tap a keystroke and you just saved a ton of typing.
I found this applescript that replaces text webpage:
http://foolsworkshop.com/applescript/2008/05/an-applescript-replace-text-method/
If you use that you can use applescript with a list separated by commas copied to the clipboad:
set theText to the clipboard
set theReplacedText to replaceText(", ", "\", #\"", theText)
return theReplacedText
then copy the results to the clipboard and paste them where you want. I'm not sure how to get it to activate with a keystroke and replace the selected text a little more neatly.

Is it not the same as in other languages like so NSString *string = #"Some text here /"Here is the text/" ";

Related

Can you replace a variable and its value in all open files in visual studio code?

I was wondering if it is possible to replace all instances, in all open files of this construction time variable in visual studio code, they all have different number values after the colon. For ex. Replace all occurrences of "constructionTime":xxxxx, with "constructionTime":10,
Construction time variable
Yes it is.
Open up the edit menu then select "Find and Replace".
After that select "Replace in Files". A small dialog should open.
Under "Find Options" select "use regular expressions"
Select the "Look in" drop down, drop it open, so you can select "All Open Documents".
In the "Find what field" input, type: "constructionTime":* . <--- space after *
In the Replace with field type: "constructionTime":10 .
Then either hit Find Next and Replace on instances you wish to replace or
hit replace all.
The * is the Regular Expression Wild-Card character, and it will "find" anything it atches, that comes after it. Typically you would want to place another character after the Wild-Card, that way the search is limited, however; in your case I chose a space, but in you case you might have to try with , ; ) and the like.

Autofill Text box on a Web Page (Javascript/VBScript)

I really need to know how I can autofill text boxes on a web page.
What I really want to achieve is the following:
1) Go to http://show.websudoku.com
2) Replace all the empty cells with a 0 (zero).
Is that possible?
To fill the empty spaces of the Sudoku grid at http://show.websudoku.com with zero's, here is some JavaScript to do that. It is formatted for use as a "Bookmarklet":
javascript:(function(){var x,k,f,j,r;x=document.forms;for(k=0;k<x.length;++k){f=x[k];for(j=0;j<f.length;++j){r=(f[j].className.toLowerCase()+f[j].type.toLowerCase()+f[j].value);if(r=="d0text"){f[j].value="0";}else if(r=="d0text0"){f[j].value="";}}}})();
The setup:
Create a new Bookmark/Favorite. For now, the URL for the favorite can be anything. An easy way to do this is to drag ANY link/url from the browser address bar, or any web-page link, to the "Favorites Bar" or to the Bookmarks/Favorites sidebar.
Select the new favorite, and rename it to any name you like.
Copy the JavaScript code from above to the clipboard. It must remain as 1 continuous single line, and it must begin with "javascript:(" and end with ")();"
Edit the properties of the new favorite.
Remove the "URL" that is currently in the favorite and replace it by pasting in the JavaScript code from above, into the "URL" text field for the favorite, then save the changes.
To use the bookmarklet:
From the browser, navigate to http://show.websudoku.com as you normally would.
Click the new favorite (Bookmarklet) that you just edited.
All empty spaces in the Sudoku grid will be filled with 0's. Click the new favorite (Bookmarklet) again, and the 0's will be removed leaving empty spaces once again.
Here is what the Javascript code looks like expanded, with indents:
javascript:(function(){
var x,k,f,j,r;
x=document.forms;
for(k=0;k<x.length;++k){
f=x[k];
for(j=0;j<f.length;++j){
r=(f[j].className.toLowerCase()+f[j].type.toLowerCase()+f[j].value);
if(r=="d0text"){
f[j].value="0";
}
else if(r=="d0text0"){
f[j].value="";
}
}
}
}
)();
* Spoiler alert *
In case you want to "cheat", the JavaScript here will "solve" the Sudoku:
javascript:(function(){var x,k,f,j,ecl,etl,en,ev,s,e,c,d,dl,dr,n;x=document.forms;for(k=0;k<x.length;++k){f=x[k];for(j=0;j<f.length;++j){e=f[j];r=(e.name.toLowerCase());if(r=="cheat"){c=e.value;break;}}for(j=0;j<f.length;++j){e=f[j];ecl=e.className.toLowerCase();etl=e.type.toLowerCase();en=e.name;ev=e.value;if(etl=="text"){if(ecl=="d0"){dr=en.substr(en.length-1,1);dl=en.substr(en.length-2,1);d=(((Number(dr)-1)*9)+Number(dl))-1;n=c.substr(d,1);if(ev.length==0){e.value=n;}else{e.value="";}}}}}})();
Setup and use is the same as described above.
While it's not much fun to solve it like that (OK, maybe it's a little fun the first couple times), and definitely not challenging, if you are in a real-real-real hurry, you can solve it in 1 click.
Note: I have only tested these 2 bookmarklets with IE9.

How do I bind a non-breakspace(alt-288 or  ) upon pressing the space bar in javascript?

I'm using OpenMRS, it's an opensource medical records system. OpenMRS has a built-in html editor and I use this mostly in javascripting ang building the forms. In one of my forms,I have a textarea. My client would like his entries(in paragraph or in list) to be indented in the textarea.
Now when you try indenting the paragraph in the textarea then save the changes and preview the form, the paragraph becomes justified instead of retaining the indented lines.
However, if I try indenting the paragraph using ascii code for non-break space by typing   or pressing alt-288, the paragraph becomes indented thus giving me the desired result. Now, the users don't prefer typing or pressing ascii equivalents coz that'll be hassle on their part.
I'm using mostly javascript and jQuery because it's what openmrs supports. If I could somehow bind the non-break space character upon pressing a key then this will work, but I'm at a lost here. How will I do this in javascript or jquery?
One solution which might work for you is to replace leading spaces in the textarea when you process/save or even each time it changes it something like :
ta.value = ta.value.replace (/\n +/, function (m) {
return '\n' + Array (m.length).join ('&#160');
});
The Array ... constructs creates an array containing length elements then joins with your non-breakspace character effectively creating a string of that many space chars.
Another possibility is to watch for space characters entering the text-area and transforming them. See here : Can I conditionally change the character entered into an input on keypress?

Determine visible characters to be highlighted using html source

I'm using TinyMCE to let users edit and format text, output is html code.
The html is then sent to the server and is pushed to other clients that can follow the edit progress on a webpage, the html is inserted into a div so users can see the format but they are not able to edit.
Now I want the cursor position and any selection the user makes in the editor to show up on the readonly page using highlight(background color) if selected or inserting an empty span with a black border between characters to imitate the cursor position.
I made an attempt using
editor.tinymce().selection.getRng()
which gives me the start and end position of what the user sees(formatting characters are not counted)
Then I traversed the DOM and counted the characters in every text element wrapping the ones selected with a highlight span. This resulted in messy code but worked pretty well until I hit a non ascii or encoded character in the textblock.
Example html
<p>abc <b>de</b>fg</p>
looks like this to the user
abc defg
Say user selected character c to d (selection covers c, a blank, first half of the bold tag and d),
tinymce will return range start:2 end:5
but the actual characters behind would be start:5 end:16.
Just wrapping the text from char 5 to 16 in a highlight span will result in bad html.
Checking for words starting with & and ending with ; and adding number of positions will turn into a mess. There has to be a simpler way
How do I calculate how many "visible" characters a set of html character will turn into?
Or maybe you would attack the problem in another way
Thanks
PS 1
I've looked into the various jquery highlight plugins but they seem to highlight based on a search string. Those does not work in the case user selects one character and that character exists several times, they will then highlight all occurences.
I've tackled this problem in my Rangy library: the TextRange module concerns itself with the text the user sees. It sounds like you need the selectCharacters() and toCharacterRange() methods of Rangy's Range objects.

jquery autocomplete on last word

I'm trying to edit this js code so that the autocomplete function kicks in after each non-breaking space; regardless of whether or not the text entered before each non-breaking space was one of the tags. So, for example, if I enter PHP, that's one of the tags. But, if for the next text that I enter, it must be one of the tags too otherwise anything that I enter after PHP will not activate the autocomplete. You can find this example on jsfiddle
I think that you're looking for a plugin like this one:
http://levycarneiro.com/projects/tag-it/example.html
- or -
http://code.drewwilson.com/entry/autosuggest-jquery-plugin
Basically you need to look for "jQuery Autocomplete Tags" instead of just "jQuery Autocomplete".

Categories