Tab spaces
Any directions on how to enable tab spaces in the .editable class ?
@manishmshiva Do you mean to add spaces by pressing tab key ? If yes, I do not think there is any option to do that.
If as @rishijain said, you're wanting to add the Tab character into the content of the editor i.e. /t - some extra functionality will need to be added. The default function of the TAB key when in a textarea is to move the cursor to the next available input.
If you look at the bindTab function here; https://github.com/createdotnet/medium-editor/blob/master/dist/js/medium-editor.js#L464-L487
There's some functionality to allow tabs in <pre> blocks, and to indent lists items.
Essentially if you were to remove the if statement; if (tag === 'pre') { - you should be able to insert tabs.
The code that @Dayjo is talking about is now here in the latest master.
This is an extension that will indent and unindent using the tab key except when inside a pre block.
(function(root, factory) {
'use strict';
if (typeof module === 'object') {
module.exports = factory;
} else if (typeof define === 'function' && define.amd) {
define(factory);
} else {
root.TabIndent = factory;
}
}(this, function(MediumEditor) {
var TabIndent = MediumEditor.Extension.extend({
name: 'tabIndent',
init: function() {
this.subscribe('editableKeydownTab', this.handleTabKeydown.bind(this));
},
handleTabKeydown: function(event) {
var node = MediumEditor.selection.getSelectionStart(this.base.options.ownerDocument),
tag = node && node.nodeName.toLowerCase();
// Excluding default Tab functionality
if (!MediumEditor.util.isListItem(node) && tag !== 'pre') {
event.preventDefault();
// If Shift is down, outdent, otherwise indent
if (event.shiftKey) {
this.base.options.ownerDocument.execCommand('outdent', false, null);
} else {
this.base.options.ownerDocument.execCommand('indent', false, null);
}
}
},
});
return TabIndent;
}(typeof require === 'function'
? require('medium-editor')
: MediumEditor)));
Example usage:
var tabIndent = new TabIndent();
var editor = new MediumEditor('.editable', {
buttonLabels: 'fontawesome',
extensions: {
'tabIndent': tabIndent,
},
})
If @aahoo or anyone would like to build this out as an actual extension in a separate repo/npm package, we'd be happy to mention it in our list of known extensions in the documentation and our landing-page.
Otherwise, please use the above code as a reference for how to add this into your project.
Thanks for sharing @aahoo !