Skip to content

Commit

Permalink
add insert table to toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
jhchen committed Apr 23, 2018
1 parent f461565 commit 608fd58
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions assets/core.styl
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ resets(arr)
margin-right: -1*LIST_STYLE_OUTER_WIDTH
text-align: left

table
table-layout: fixed
width: 100%

.ql-code-block-container
font-family: monospace

Expand Down
3 changes: 2 additions & 1 deletion modules/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ Keyboard.DEFAULTS = {
},
tab: {
key: 'Tab',
handler(range) {
handler(range, context) {
if (context.format.table) return true;
this.quill.history.cutoff();
const delta = new Delta()
.retain(range.index)
Expand Down
16 changes: 16 additions & 0 deletions modules/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import Module from '../core/module';

const debug = logger('quill:toolbar');

let tableId = 0;

class Toolbar extends Module {
constructor(quill, options) {
super(quill, options);
Expand Down Expand Up @@ -258,6 +260,20 @@ Toolbar.DEFAULTS = {
this.quill.format('list', value, Quill.sources.USER);
}
},
table(value) {
if (!value) return;
const range = this.quill.getSelection();
if (range == null) return;
// Insert 2x2 table
this.quill.updateContents(
new Delta()
.retain(range.index)
.insert('\n\n', { table: { row: (tableId += 1) } })
.insert('\n\n', { table: { row: (tableId += 1) } }),
Quill.sources.USER,
);
this.quill.setSelection(range.index, Quill.sources.SILENT);
},
},
};

Expand Down
2 changes: 2 additions & 0 deletions ui/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import listOrderedIcon from '../assets/icons/list-ordered.svg';
import subscriptIcon from '../assets/icons/subscript.svg';
import superscriptIcon from '../assets/icons/superscript.svg';
import strikeIcon from '../assets/icons/strike.svg';
import tableIcon from '../assets/icons/table.svg';
import underlineIcon from '../assets/icons/underline.svg';
import videoIcon from '../assets/icons/video.svg';

Expand Down Expand Up @@ -67,6 +68,7 @@ module.exports = {
super: superscriptIcon,
},
strike: strikeIcon,
table: tableIcon,
underline: underlineIcon,
video: videoIcon,
};

0 comments on commit 608fd58

Please sign in to comment.