Return key is not handled in cell editor - mxgraph

I'm studying mxGraph examples and have the following problem. When I double-click a cell and edit in-place its content, I assume that pressing Return key should end editing and set the cell's content to the newly typed. But instead pressing the Return key works as usually in editors: it moves the caret to the new line.
Why I assume that Return should stop editing? Because comments say so (e.g. in userobject.html):
// Stops editing on enter key, handles escape
new mxKeyHandler(graph);
And also because there would be no convenient way to end cell editing apart from clicking with the mouse somewhere outside the cell. (By the way, Escape key is handled OK: it also ends editing, but without updating the cell content.)
This behaviour is observed in all browsers I tried: Firefox 60 on Linux, Firefox 52 and IE 11 on Windows.
Why this problem exist and how can it be solved?

Have you tried graph.enterStopsCellEditing = true? See https://jgraph.github.io/mxgraph/docs/js-api/files/view/mxGraph-js.html#mxGraph.enterStopsCellEditing

Related

Turn off automatic space insertion on macOS

When you copy then paste the string “word”, macOS sometimes inserts “word” (unchanged), “ word”, “word ”, or “ word ”, depending on what you’re pasting it next to, whether it thinks you copied it as a word or as a range, and whether you’re pasting into a writing input (like a note in the Notes app) or a string input (like Safari’s URL bar). Click-and-dragging to select results in a range copy, double clicking results in a word copy.
On macOS, Safari and Chrome perform automatic space insertion in all inputs, while Firefox performs it in none. Firefox also does not follow the native behavior for double clicking a word, right clicking a word, or copying a word.
You can play with the behavior with the following demo. Try double clicking a word then pasting it multiple times, then try selecting a word by dragging then pasting it multiple times.
<div>one two three</div>
<input>
Automatic space insertion is probably fine and intuitive for macOS users, but is sometimes inappropriate for the same reason it’s inappropriate in Safari’s URL bar: some contexts are not in English or any other written language. In these contexts, automatic space insertion leads to surprising results. For example, I ran into this issue when entering input in a micro-language of the form [field.{id}], then pasting an ID, which was copied as a word, then getting [field. {id}] and the error that it caused.
Ideally, I want to instruct the browser not treat an input’s value as writing. Minimally, I want to turn off automatic space insertion an inputs. How can I do this?
Things I’ve tried that didn’t work:
Setting lang="" or lang="none" on both the input and the copied text
Setting lang="zh" on both the input and the copied text (Chinese languages do not use spaces between words)
Setting spellcheck="false" on the input
Setting autocorrect="off" on the input (non-standard, Safari only)
One solution is to cancel then mimic the paste event in JS.
<input id="example">
document.querySelector('#example').addEventListener('paste', e => {
e.preventDefault();
const pastedText = e.clipboardData.getData('text/plain');
document.execCommand('insertText', false, pastedText);
});
This solution has the following limitations:
Requires JS
Does not also disable other writing-specific niceties, if any exist
Uses the deprecated document.execCommand API

Sublime Text 3 - Hitting tab doesn't add space, instead makes text lower case

If I were to type the following:
TEST
Then hit TAB, the code would now look like this:
test
I don't know what happened, but tab is not indenting anymore and changes the text on the current line to lowercase.
Any idea how to restore the TAB function?
One possible reason for this in the general case is that you have installed a third party package that's stolen the Tab key binding in order to perform it's own action, which in this case would be turning the prior word lower case.
This will be the case if this behaviour holds true for any word that you happen to press Tab after. In that case the solution would be to find the package that's doing this and disable or reconfigure it.
In your case I think the more likely cause for this is that in the file you're currently editing the word TEST appears, and you have the following setting turned on:
// When enabled, pressing tab will insert the best matching completion.
// When disabled, tab will only trigger snippets or insert a tab.
// Shift+tab can be used to insert an explicit tab when tab_completion is
// enabled.
"tab_completion": true,
When the setting is set to true (which is the default), pressing Tab will attempt to perform a tab completion, which considers not only snippets and completions but also words in the current buffer as well.
In that case, if you were to enter the word test and press Tab at a point where the word TEST also appears in the buffer, it's considered a potential completion and will become the replacement.
If this is the problem you would see similar behaviour by just entering t and pressing Tab, which would cycle through all of the T words in the buffer as possible completions.
Assuming this is what's happening to you, one of the following should fix the problem for you:
Set tab_completion to false in your preferences; this will disable the feature entirely everywhere
Set tab_completion to false only in the settings of the specific file type that you're having the problem in; that would leave the feature enabled in the general case but stop it from occurring in the files that you don't want it to occur in.
Use Shift+Tab instead; that key sequence will do what Tab normally does and insert a tab character even if Tab would try to do a completion.
For #3 to work, make sure that you have this setting set as follows:
// By default, shift+tab will only unindent if the selection spans
// multiple lines. When pressing shift+tab at other times, it'll insert a
// tab character - this allows tabs to be inserted when tab_completion is
// enabled. Set this to true to make shift+tab always unindent, instead of
// inserting tabs.
"shift_tab_unindent": false,
The default for this value is false, in which case as the comment mentions the binding will perform a tab unless you have multiple lines selected in which case it unindents instead.

When I create a new class="" the cursor starts outside the quotes in PhpStorm. How can I get it to go between the quotes so I can continue typing?

When I type in class="" it autofills and puts the cursor after the closing quote.
This means I need to delete a quote to enter the class name or click between them. Both of which ruin my workflow.
Is there a way to put the cursor inbetween the quotes in settings? And if there is, is there a way to jump out of the quotes and keep adding to my markup?
In Sublime Text it puts the cursor in the class and then tab takes you outside of it. I'm sure PhpStorm can do the same.
Instead of typing the whole class="" thing by yourself -- just let IDE autocompletion to do the job for you.
Just two characters (cl) is enough to make class entry first in the list (unless you have used some other similarly named attributes/properties recently that would temporarily bring them higher than class):
Completing with Enter will have the text inserted into current position with caret located in the right place class="[CARET_HERE]".
Completing with Tab does the same but replaces the text that is currently under caret (useful when changing class/image name/function/etc completely).
If standard code completion is not good enough for some reason or you do not like automatic completion popop (and prefer invoking it manually only when needed) -- you will be interested in Live Templates functionality that allows creating some abbreviation and expanding it into the final snippet with minimal key presses (e.g. cl[Tab] into class="|")
IDE also has options to:
insert quotes ("" or '') after typing = in XML/HTML attributes.
Settings/Preferences | Editor | General | Smart Keys --> Add quotes for attribute value on typing '=' and attribute completion
insert pair quotes (closing one) when entering opening one -- works in different contexts/languages. It will "eat" the closing quote preventing you from typing too many.
Settings/Preferences | Editor | General | Smart Keys --> Insert pair quote
In Sublime Text it puts the cursor in the class and then tab takes you outside of it. I'm sure PhpStorm can do the same.
If I understood you correctly (sorry, never used Sublime myself) -- No... and may not have it for quite some time (devs say that the way how IDE works somehow conflicts with proposed Tab or Esc behaviour).
Better explanation/arguments from both sides can be found in actual ticket: https://youtrack.jetbrains.com/issue/IDEABKL-6984

Use hard tabs instead of spaces in BlueJ

In BlueJ, if a file is using hard tabs BlueJ will automatically convert the entire file to use spaces instead of hard tabs. I'm looking for a way to tell BlueJ not to convert hard tabs into spaces.
According to Replacing Tabs with Spaces (posted by Michael Kölling, developer of BlueJ), tabs are converted to spaces under the default settings the first time you enter a tab.
If your preference is set to use spaces (i.e. the TAB key is bound to
the 'indent' function, not to the 'insert-tab' function) -- this is the
default -- then the first hit of a TAB key in a newly opened file will
replace all TABs in that file with spaces.
In other words, if you get a file that contains TABs, editing this file
with the BlueJ standard settings should remove TABs from that file. (I
did not want to change the TABs on file-open, because I did not like
the idea of the file changing on disc if you do not actively edit it.)
To change this setting so that you can enter an actual TAB character, go to Options > Key Bindings, then select Edit Functions from the Categories drop down list. There are two changes you'll have to make.
Scroll down to indent. By default it should be set to the Tab key. This setting is what's inserting soft spaces by default. Click on Tab under Key Bindings, then click the 'Delete Key' button.
Scroll down to insert-tab. Delete the existing key binding and add the Tab key here so that pressing that key will insert a TAB character.
Here's what the screen looks like with the default settings.
There you can see that the Tab key is set to the 'indent' function, which inserts soft spaces. Making the changes above will prevent that from happening.

How do I configure Emacs html-mode to behave like TextMate's default HTML bundle?

A friend of mine is considering switching to Emacs from TextMate. He is used to TextMate's default HTML editing mode which has 4-space tab stops and inserts tab characters (i.e. it does no auto-indenting by default). It also allows completion of open HTML tags with "Cmd-Shift->". Any ideas?
I think these settings should do the trick:
(defun my-html-mode-hook ()
(setq tab-width 4)
(setq indent-tabs-mode t)
(define-key html-mode-map (kbd "<tab>") 'my-insert-tab)
(define-key html-mode-map (kbd "C->") 'sgml-close-tag))
(defun my-insert-tab (&optional arg)
(interactive "P")
(insert-tab arg))
(add-hook 'html-mode-hook 'my-html-mode-hook)
An explanation of the settings in 'my-html-mode-hook is as follows:
set the tab width to 4
force tabs to be inserted (as opposed to spaces)
force the TAB key to insert a tab (by default it is bound to do indentation, not just insertion of tabs
'sgml-close-tag is the command that inserts a close tag for you, and this setting gets you the keybinding you want
I'm having a bit of a brain freeze and couldn't figure out the simple way to have the TAB key insert a TAB character, so I wrote my own. I don't know why a binding to 'self-insert-command didn't work (that's what normal keys are bound to).
The last line just adds the setup function to the 'html-mode-hook. The key bindings really only need to be run once (as opposed to every time html-mode is enabled), but this is a little easier to read than using 'eval-after-load. It's use is left as an exercise to the reader.
I don't know about emacs's HTML modes specifically, but I can answer about general editing:
by default, Emacs doesn't autoindent, so nothing to do here.
Emacs preserves tab characters, unless you explicitely ask them changed (check out tabify and untabify). Their width is determined by the buffer-local tab-width variable. M-x set-variable, (setq...), customize at will.
you should be able to get the behavior you want with the tab key by setting indent-line-function to tab-to-tab-stop, setting tab-stop-list to (4 8 12 16...) and indent-tabs-mode to t.
Setting indent-tabs-mode allows Emacs to insert tab characters when indenting. The tab-to-tab-stop is a form of indentation that only goes to specific positions in the line, which we set to match the expected behavior of the tab characters by setting tab-stop-list to the multiples of 4.
About completion, the only thing my muscle memory tells me is "C-c C-e", but I don't remember for sure which major mode it's supposed to go with. The closest I see in the list is sgml-close-tag, bound to C-c /
A bit of politics: don't use tab characters, especially if you use widths not equal to 8. It only results in unpredictable results