I've been using TinyMCE (v4 at the moment, but this question is valid for v5 as well) as an editor for content that is eventually turned into Word documents.
Pressing shift + enter on TinyMCE inserts a line break <br /> rather than a return (i.e., creating a new <p>). Is there any way to make shift + enter behave just as enter? In other words, is there any way to disable shift + enter?
If anyone's interested as to why I'm asking:
To make it as similar to editing text on Word as possible, I made it so that <p> elements have no margins at all. This way, the document looks the same on the editor and on Word. Line breaks look the same on the editor, but when converted to Word, their behaviour is different when the text orientation is set to justified. Lines ending with a line break get stretched to the full width of the document; lines ending with a return don't get stretched at all. That's the behaviour I'd like to have.
TinyMCE has APIs you can use to be notified when a key is pressed and you can look at that event to see if Shift + Enter has been pressed. The code to do this can go in your configuration:
setup: function(editor) {
editor.on('keydown', function (event) {
if (event.keyCode == 13 && event.shiftKey) {
console.log(event);
event.preventDefault();
event.stopPropagation();
return false;
}
});
}
Here is a complete TinyMCE Fiddle: http://fiddle.tinymce.com/LQgaab
Related
I have an empty span and I would like to set cursor position on it. My codes works in Edge, Chrome, FireFox but not for IE.
I have tried set cursor on empty tag but the solution is not applicable for me.
This is the sample empty span:
<span id="ABC"></span>
My codes to set cursor position:
ed.on("focus", function (e) {
ed.focus();
var node= ed.dom.select("span#ABC");
ed.selection.setCursorLocation(node[0], 0);
});
The technique we use in the editor is adding a zero-width character ("\uFFEF" in JS) into the span and selecting that. It's a fairly reliable cross-browser way to put the cursor in places the browser doesn't normally support.
These characters are stripped when the content is serialised so there's no impact on the output HTML.
My PHP generates a Word document, but it will not render carriage returns. My CKEditor translates a carriage return into either,
<br>, or <div>asdf</div>
When the Word document is created, it will display those HTML tags, so I strip them out. What replacement code, character, ascii, or tag can I use so that when the page is rendered, it shows the text like it did in the Editor?
Current example - if you have the text "Don't jump off the" [then hit Enter, so that the next word is below it]...
"cliff." Instead, currently, that gets saved into SQL as:
Don't jump off the <br>cliff.
Don't jump off the <div>cliff</div>.
...depending on which browser is used. In the msWord output, any tags left in the content [exceptions to strip_tags function] get displayed literally in msWord. Or, if I replace the tags with ASCII
it displays that literally, too. Not sure if this helps, but this is defined at the top of my php report_generator.php file:
require_once '/var/www/PhpWord/src/PhpWord/Autoloader.php';
\PhpOffice\PhpWord\Autoloader::register();
include "/var/www/ncpcphp/NCPC_PHP_Functions.php";
DEFINE("WRITEtoFDOCS", "NO");
DEFINE("FDOCSDIRECTORY", "Contract Attachments");
DEFINE("MIMETYPE","application/vnd.openxmlformats-officedocument.wordprocessingml.document" );
Help - what can I use to cause the output to show the carriage return?
Thank you, Cindy. Your answer is a piece of the solution. My CKEditor saves carriage returns as either
<br>, <br />, or <div></div>
depending on which browser is used Chrome[div] or Firefox[br] - that goes into my msSQL. Yet, if my editor has turned-on an "Enter filter" [keycode-13] in order to prevent someone from enter-editing a [[Placeholder]] (ckeditor read-onlyplugin) then saved editor text strips out the Enter. So, I did this: kept in the enter filter because it is necessary, then after the text carriage returns are saved as br's or div's, when I run my report generator, I replace
<br>, <br />, and <div></div>
with "\n" like you said. Then I explode the text variable like this:
$show_cad = explode("\n", $show_cad);
foreach($show_cad as $line) {
$section->addText(htmlspecialchars($line));
}
The code in the editor needed to filter out the Enters only when Enter is pressed in the [[Placeholder]] plug in is more complex, and I got largely from CKEditor themselves. They request that I do not post their full solutions, but if you like I could show you pieces of it. Basically, I had to register the Placeholder widget. Then when Enter is pressed, it checks if the context is with Placeholder. If so, filter the Enter [then it disappears from the saved editor text], but if Enter is pressed elsewhere, it gets saved and used properly.
Thank you for your help!
I'm trying out VS Code and I used Emmet to create a new HTML element with a class. I need to create another nested (child) HTML element inside the original element, but by default, VS Code will not indent for the new element, when you hit enter inside the original element tags. Like if you have <div class="main"></div> and you hit enter in between the div tags, you'll get -
<div class="main">
</div>
And then you need to manually go one line up, add tabs and indent for the new HTML element.
In Webstorm, hitting enter in between the parent tags automatically indents for the new child element.
Here are two GIFs which show what I mean.
VS Code -
Webstorm -
Is there an extension or some other trick that achieves this feature in VS Code?
Download an HTML formatter Extension. 1th, download one of the below Extensions:
Beautify
JS-CSS-HTML Formatter
OR any other HTML formatter you want. 2th, in VS Code, go to one of the HTML files you are working. 3th, Press ALT + SHIFT + F then a pop out window appears. 4th select one of the suggested formatters. All done!
Whenever, you press ALT + SHIFT + F in an HTML file, it will be auto indented and beautified.
I'm guessing your looking for this setting
{
...
"html.format.indentInnerHtml": true,
...
}
"emmet.useNewEmmet": true;
Use this command to enable indent.
Steps:
1) Open "settings.json".
2) Add this code inside { ..... } (Curly Braces).
3) Make sure you add ',' (comma) on the last line if you are adding this code after a certain line in the end.
eg:
{
...
...
"editor.fontSize": 17, <--comma
"emmet.useNewEmmet": true
}
4) Save it.
FROM: https://github.com/Microsoft/vscode/issues/30790#issuecomment-317290906
I want to know if there is a way to highlight the full content in an expression like if, while, etc.
I have to work in a code that is bad indented where expressions can cover over 1000 lines and I can't format it.
for exemple :
if ($somethingTrue) {
while ($somethingHappen) {
// 500 lines...
} }
if ($someCondition) {
}
look, it's very hard to see the end of the first if and what it cover...
Does someone know if there is a native feature or plugin on netbeans that do this job ?
Thanks !
You don't need any plugin/external jar file for achieving the same. Whichever expression you want to check the body of, just click on the opening brace after that expression and NetBeans will automatically show you the closing brace for that expression.
Basically, Netbeans shows the ending brace for a corresponding starting brace entry---for each of if-statements,loop-statements,method declarations,etc.
In the shown figure, see my if-statement starting with yellow brace(cursor blinking there), and the corresponding ending brace for the if-statement.
EDIT :-
You also can also have a brand new-code fold,just by typing fcom, and hitting (Tab) button on KeyBoard. And, then put whatever block you want inside it and done. Expand whenever you wish and collapse whenever you want.
Check the position of my mouse-pointer which shows the current block of if-statement. You can expand and collapse as per your wish. And, also you can have several of them for each of your expression-tree.
I want to edit multiple lines in eclipse, but I can't find any short cut or Plugin. In Geany I just press ctrl+alt+up/down I can add / edit multiple lines.
Maybe this example can explain what I mean:
var text = "myname";
var addr = "myaddr";
var age = "myage";
I want to edit text above into:
var my_text = "myname";
var my_addr = "myaddr";
var my_age = "myage";
The text above is just a simple example, but sometimes I have many lines of words that I have to edit its prefix.
Press alt + shift + A to Toggle block selection (Toggle block / column selection in the current text editor), this will let you write vertically in eclipse, then you can easily do this.
Go to Window->Preferences.
Find for binding in text box surrounded by red box.
On OS X, the key combination for multi-line edits in Eclipse (or STS) is option/alt+command+A
You can try the following plugin,
https://github.com/caspark/eclipse-multicursor/releases
With this multiple occurrence of same text can be selected and edited. This is similar to multi select functionality available in editors like Sublime and Visual studio code.
The Eclipse 4.24 (June 15 2022) will integrate it (See https://bugs.eclipse.org/bugs/show_bug.cgi?id=576377):
Multi selection down relative to anchor selection (e.g. Ctrl-Alt-J)
Multi selection up relative to anchor selection (e.g. Alt-J)
End multi-selection (e.g. ESC)
Add all matches to multi-selection (e.g. Ctrl-Shift-Alt-J)
Multi caret up (e.g. Ctrl-Alt-Shift-Up)
Multi caret down (e.g. Ctrl-Alt-Shift-Down)
Thanks to eclipse contributor !
The Eclipse 4.22 (Q4 2021) equivalent of Geany would Alt+Click on the lines you want to edit in one go.
Eclipse now supports
Multiple text selection
Support for multiple selection has been added to Text Editors.
Multi selections allow most edit operations (text replacement or insertion, extend selection to next word or to next line, copy/paste...) to apply simultaneously on all ranges.
Multiple strategies are available to enable multi-selections:
Turn a block selection into a multi-selection using the To multi-selection command,
Add a caret with Alt+Click,
Use the new Select All button on the Find/Replace dialog.
So check if this would work in your case.
I know this is an old post, but I still want to share my way of multi select and editing. However this way is restricted to only the same variables across the file. Simply highlight the variable to edit, right click, choose Refactor->Rename. Then edit the variable and it will also edit the same variables across the file. Hope it helps..:)
Press key - { Alt + Shift + A } You will see A [+] symbol in IDE then use this symbol as drag