This is a follow up question to this topic:
Creating custom keyboard controls [Elm]
I'm adding a feature that allows players to customize controls. But the way arrow keys represent themselves is really weird. I'll get to that in a bit. What I have looks like this:
ck2up : Input [KeyCode]
ck2up = input [toCode 'W']
ck2down : Input [KeyCode]
ck2down = input [toCode 'S']
ck2left : Input [KeyCode]
ck2left = input [toCode 'A']
ck2right : Input [KeyCode]
ck2right = input [toCode 'D']
They receive input from Keyboard.keysDown while I'm clicking a button. This works fine for normal Char input, but when I want to use symbols I get some weird things. I wanted to give one player arrow keys by default, but since it has to be customized, I cannot use Keyboard.arrows. Player one will have:
ck1up : Input [KeyCode]
ck1up = input [8593]
ck1down : Input [KeyCode]
ck1down = input [8595]
ck1left : Input [KeyCode]
ck1left = input [8592]
ck1right : Input [KeyCode]
ck1right = input [8594]
This is taken from http://character-code.com/arrows-html-codes.php. These are the html codes for the arrow keys. I show the current keys on my buttons and the arrows show up properly:
(button ck1up.handle kd (append "up: " (fromList [fromCode pkeys1.up])))
with pkeys1.up containing the keycode. However, ingame the arrow keys don't respond. This is to be expected since html is made for layout, but when I try to use the unicode, as described http://library.elm-lang.org/catalog/elm-lang-Elm/0.13/Char toCode and fromCode, the keys ingame still don't work and I get an error icon where I expected the arrow symbols on the buttons. This might be because the unicode is in hexadecimals.
But! I can use my newly gained feature to customize controls by holding down keys while pressing a button. This did make my arrow keys work, but it showed the following symbols instead:
up: &
down: (
left: %
right: '
This means that the same unicode that made my arrow keys functional, are displaying these random symbols. Isn't that weird? If anyone know where I can find the unicode values Elm uses, that'd be great. I want to set up the arrow keys as default if no keys are entered. Does anything exist to convert these unicode to html as well, for proper display?
In case it matters, I'm still using Elm version 13.
Update
So I figured out the KeyCodes 38, 40, 37 and 39 respectively correspond to the arrow characters (and the display symbols correspond to these same values, but in html).
As you've already figured out, key codes 37-40 are the ones you need. These can also be found in the source code of Keyboard.arrows.
KeyCode is not just some random name but alludes to JavaScripts keycodes being used. I cannot find the definition with a quick search in the ECMAScript docs and other internet sources suggest that browsers were not always compatible in their use of keycodes. So this is your standard web-programming mess that's getting slowly easier to deal with. That this bleeds through into Elm is arguably bad design though, best continue this discussion on the mailing list.
Related
I want to add small straight line onto some desired characters/numbers inside a string inside textview. I couldn't find a solution. Maybe using NSMutableAttributedString. Meanwhile, I mean doing this programmatically. There is strikethrough style, but not overstrike style. Or maybe adding the letters "a" and "_" with different .baseline values. But how to add both characters onto each other then?
Is it possible?
EDIT: Due to make a try for the helpful answers below, I think to make the line at a spesific height is needed. "A\u{0305}" makes the up line very close to the character, as if it sticks. Is there a way to make it at specific height? For example, if we assume that all the keyboard-inputted characters are written inside every single boxes, the ceiling side of these boxes could be lined?
So this (note: see edit below) appears to be an "a tilde ogonek" (it's Lithuanian).
You can write it for instance as follows using these two Unicode characters:
let atildeogonek = "\u{0105}\u{0303}"
let title = "How to add a small straight line (I mean like this: \(atildeogonek)) onto a character inside a string?"
The first character is the a with an ogonek, the second one is the tilde.
EDIT: The initial question specifically asked about the character ą̃ ("a tilde ogonek") in the title, and I used this code to demonstrate how to use Unicode characters in a Swift string. After posting this answer, the question was edited to be more general about "a line above a character".
Programmatically, you could use a function like this:
func overline(character: Character) -> Character? {
return "\(character)\u{0305}".first
}
That will take a character as input and return a new character (glyph) that has had the Unicode combining overline character added to it. It will return nil if adding the combining overline character fails.
The code print(overline(character:"A")!), for example, returns "A̅"
Or, if you want to add an overline to every character in a string, you could use a function like this:
func overline(characters: String) -> [Character?] {
return Array(characters).map { return "\($0)\u{0305}".first
}
}
(I'm not sure if there are any characters for which the above will fail, so I'm not sure if force-unwrapping the result is safe. Thus I left the result of both functions to be optional Character/Array of Character.)
You can easily find the unicodes of ā or ą̃ by using the xcode's own Character Viewer. Just follow the following steps :
hit : Control + Command + SpaceBar
If you get a compact one like this, click the upper right corner icon to expand it.
When expanded, Click the settings gear in the corner . Select customize list.
select Enclosed Characters
Go down to the bottom and open Code tables then add Unicode.
Now, just search for your required Character and you can check its unicode value. here i am searching ā
to print unicode's value :
print("\u{0101}")
Having trouble finding a way to do this, maybe it is not even possible?
In my case, for testing flow of if-statements/user-interaction, am temporarily adding 40 lines of console.log('trigger-fired-1'); throughout our code.
However, to tell them apart would like each to end with a different number, so in this case, numbers one to forty like so:
In the screen recorded gif, to replicate what I am going for, all I did was copy/paste the numbers one to nine. What I really would like is a shortcut key to generate those numbers at the end for me to eliminate that step of typing out each unique number.
Am primarily coding in Visual Studio Code or Sublime Text, and in some cases shortcuts are similar, or at least have same support but for different shortcut keys.
There are a few extensions that allow you to do this:
Text Pastry
Increment Selection
NumberMonger
For Sublime Text, the solution to this problem is the internal Arithmetic command. Something similar may or may not be available in VS Code (possibly with an extension of some sort) but I'm not familiar enough with it to say for sure.
This command allows you to provide an expression of some sort to apply to all of the cursor locations and/or selected text.
By way of demonstration, here's the example you outlined above:
The expression you provide is evaluated once for every selection/caret in the buffer at the time, and the result of the expression is inserted into the buffer (or in the case of selected text, it replaces the selection). Note also that when you invoke this command from the input panel (as in the screen recording) the panel shows you a preview of what the expression output is going to be.
The special variable i references the selection number; selections are numbered starting at 0, so the expression i + 1 has the effect of inserting the selection numbers starting at 1 instead of 0.
The special variable x refers to the text in a particular selection instead. That allows you to select some text and then transform it based on your expression. An example would be to use x * 2 immediately after the above example (make sure all of the selections are still present and wrapping the numbers) to double everything.
You can use both variables at once if you like, as well as anything in the Python math library, for example math.sqrt(i) if you want some really esoteric logs.
The example above shows the command being selected from the command palette interactively, where the expression automatically defaults to the one that you want for your example (i + 1).
If you want to have this as a key binding, you can bind a key to the arithmetic command and provide the expression directly. For example:
{
"keys": ["super+a"],
"command": "arithmetic",
"args": {
"expr": "i+1"
},
},
Try this one ...
its not like sublime
but works g
https://github.com/kuone314/VSCodeExtensionInsertSequence
Org user who relies heavily on the org-pretty-entities feature to display portions of equations and chemical formulas.
Recently, I created a custom dictionary for the purpose of using it with auto-complete.el and popup.el. I was curious if there is an existing Solution
to display UTF-8 characters in the auto-complete popup window that mimics the functionality of org-pretty-entities? If not, how could something
similar be accomplished? Thanks in advance.
Bonus Points:
I have dozens of formulas stored under ac-dictionary-files that utilize subscripts; E.g:
H_{2}O
H_{2}SO_{3}
H_{2}PO_{4}^{-}
Upon typing H_ the complete list of those that begin with H are shown (and will complete successfully), however, typing the opening bracket { causes the list to list to close and completion to fail.
Some of the entries ("H_" for example) have such a numerous amount of completions it would take more key strokes (repeatedly pressing the TAB key)
than to type the formula itself. What can be changed to enable the use and/or recognition of the { } characters by prediction?
I am writing a gui now which contains a popupmenu. This pop up menu should show different names according to cell array called titles and looks like this:
handles.titles={'time','velocity','angular velocity'};
Next, when i click on the popupmenu, i want it to plot the column which connected to this title.
so if i clicked on the 2nd popupmenu option i would like to get graph of velocity vs time.
handles.Parameter_Menu=hObject;
axes(handles.low_axis);
guidata(hObject,handles)
x_axis=xlim([handles.top_axis]);
set(hObject,'string',handles.titles(1:size(handles.matrix.Data,2)));
channel = get(hObject,'Value');
title_channel=handles.titles{channel}
plot(handles.(handles.titles{1}),handles.(handles.titles{channel}));
text=['graph of ' handles.titles2{channel} ' vs ' handles.titles2{1}];
title(text,'fontsize',12)
set(gca,'fontsize',10)
grid on
The problem occurs when i try to use title{3} because it has a space between the words.
Of course i could write it like this angular_velocity but then when i use it in title of the graph i recieve the letter "v" small because of the _ before it.
Is there any option to make it work with space or option to use it with _ but to avoid its effect in the title?
To make the title in plot displays exactly _, you can insert \ before _ (similar to latex):
handles.titles={'time','velocity','angular\_velocity'};
UPDATE:
since you are not only using the titles{i} for plot, but also use it as a struct's fieldname in other commands, then there is no way to have space, because a struct's fieldname must satisfy some conditions: Valid field names begin with a letter, and can contain letters, digits, and underscores.
So, you must use titles{3} = 'angular_velocity' to make other operations work correctly, and set Interpreter property of the title to be none to make the plot's title display as typed (default is TeX Markup, that's why i used \_ for _ above):
title(handle_of_something, titles{3}, 'Interpreter','none')
I have text files which contain code inside an Editor. The user can run an analysis on a certain part of his code, which will result in a set of lines which should be hidden. Next I want to present the user with only the remaining lines, but with correct linenumbers, as from the original document. Possible solutions I thought of:
Open a new Editor which does not contain the hidden lines, but *somehow* still has correct line numbers
Hide the lines in the original editor, and offer a button for the user to 'unhide'. Probably a similar solution required as in 1.
I don't really know how to go about this. Folds would be a weird solution, because they can be unfolded individually, and seem to be more semantically tied to things like methods or classes. Also, simply creating a new document without the hidden lines results in wrong linenumbers.
Use a ProjectionViewer and reflection to invoke the private method ProjectionViewer.collapse(int offset int length). This method is only used internally to hide a certain portion of the text, by manipulating the ProjectionDocument (see http://eclipse.org/articles/Article-Folding-in-Eclipse-Text-Editors/folding.html).
After this, folding text in the editor using the annotations(the little +/- icons) WILL break everything, so this solution and regular folding are mutually exclusive.