Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
move deletion of figures to plugins
  • Loading branch information
devrieda committed Oct 15, 2015
1 parent f291654 commit c294985
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 21 deletions.
10 changes: 1 addition & 9 deletions modules/helpers/Keys/BspaceKey.js
@@ -1,7 +1,6 @@
import CombineBlocks from '../Manipulation/CombineBlocks';
import CombineBlockPrev from '../Manipulation/CombineBlockPrev';
import ToggleBlockType from '../Manipulation/ToggleBlockType';
import DeleteFigure from '../Manipulation/DeleteFigure';

const KEY_CODES = { 'bspace': 8 };

Expand Down Expand Up @@ -29,11 +28,8 @@ class BspaceKey {
const node = document.getElementsByName(guids.anchor)[0];
const type = node.tagName.toLowerCase();

if (this.selection.isFigure() && !this.selection.isCaption()) {
results = this._deleteFigure().execute(guids);

// combine the blocks selected
} else if (this.selection.crossBlock()) {
if (this.selection.crossBlock()) {
results = this._combineBlocks().execute(guids, offsets);

// beginning of a list item converts to a paragraph
Expand Down Expand Up @@ -65,10 +61,6 @@ class BspaceKey {
});
}

_deleteFigure() {
return new DeleteFigure(this.content);
}

_toggleBlockType() {
return new ToggleBlockType(this.content);
}
Expand Down
10 changes: 1 addition & 9 deletions modules/helpers/Keys/DeleteKey.js
@@ -1,6 +1,5 @@
import CombineBlocks from '../Manipulation/CombineBlocks';
import CombineBlockNext from '../Manipulation/CombineBlockNext';
import DeleteFigure from '../Manipulation/DeleteFigure';

const KEY_CODES = { 'delete': 46 };

Expand All @@ -23,10 +22,7 @@ class DeleteKey {
const offsets = this.selection.offsets();
let results;

if (this.selection.isFigure() && !this.selection.isCaption()) {
results = this._deleteFigure().execute(guids);

} else if (this.selection.crossBlock()) {
if (this.selection.crossBlock()) {
results = this._combineBlocks().execute(guids, offsets);

} else if (this.selection.endOfBlock()) {
Expand All @@ -53,10 +49,6 @@ class DeleteKey {
});
}

_deleteFigure() {
return new DeleteFigure(this.content);
}

_combineBlocks() {
return new CombineBlocks(this.content);
}
Expand Down
2 changes: 1 addition & 1 deletion modules/helpers/Keys/OtherKey.js
Expand Up @@ -39,7 +39,7 @@ class OtherKey {

const node = document.getElementsByName(guids.anchor)[0];
let text;
if (node && node.getAttribute('data-figure')) {
if (false && node && node.getAttribute('data-figure')) {
const caption = node.getElementsByTagName("figcaption")[0];
text = caption.textContent;
} else {
Expand Down
6 changes: 6 additions & 0 deletions modules/plugins/image/index.js
@@ -1,6 +1,10 @@
import Block from "./Image";
import ReturnKey from "./ImageReturnKey";
import './Image.scss';

// figure
import BspaceKey from '../shared/FigureBspaceKey';
import DeleteKey from '../shared/FigureDeleteKey';
import '../shared/Figure.scss';
import '../shared/FigCaption.scss';

Expand All @@ -11,6 +15,8 @@ const Plugin = {

installKeys(config) {
config.use(ReturnKey, { before: 'return' });
config.use(BspaceKey, { before: 'bspace' });
config.use(DeleteKey, { before: 'delete' });
},
};

Expand Down
48 changes: 48 additions & 0 deletions modules/plugins/shared/FigureBspaceKey.js
@@ -0,0 +1,48 @@
import DeleteFigure from './lib/DeleteFigure';

const KEY_CODES = { 'bspace': 8 };

class FigureBspaceKey {
constructor(content, selection) {
this.content = content;
this.selection = selection;
}

static getName() {
return 'bspace';
}

// return or ctrl+m
matches(event) {
return event.keyCode === KEY_CODES.bspace;
}

down(callback) {
const guids = this.selection.guids();
const offsets = this.selection.offsets();

if (this.selection.isFigure() && !this.selection.isCaption()) {
const command = new DeleteFigure(this.content);
const results = command.execute(guids);
callback({
content: results.content,
position: results.position,
stopPropagation: !!results,
preventDefault: !!results,
emit: true
});
} else {
callback({ content: this.content });
}
}

up(callback) {
callback({ content: this.content });
}

_deleteFigure() {
return new DeleteFigure(this.content);
}
}

export default FigureBspaceKey;
43 changes: 43 additions & 0 deletions modules/plugins/shared/FigureDeleteKey.js
@@ -0,0 +1,43 @@
import DeleteFigure from './lib/DeleteFigure';

const KEY_CODES = { 'delete': 46 };

class FigureDeleteKey {
constructor(content, selection) {
this.content = content;
this.selection = selection;
}

static getName() {
return 'figure-delete';
}

matches(event) {
return event.keyCode === KEY_CODES.delete;
}

down(callback) {
const guids = this.selection.guids();
const offsets = this.selection.offsets();

if (this.selection.isFigure() && !this.selection.isCaption()) {
const command = new DeleteFigure(this.content);
const results = command.execute(guids);
callback({
content: results.content,
position: results.position,
stopPropagation: !!results,
preventDefault: !!results,
emit: true
});
} else {
callback({ content: this.content });
}
}

up(callback) {
callback({ content: this.content });
}
}

export default FigureDeleteKey;
Empty file.
Empty file.
@@ -1,6 +1,6 @@
import Immutable from 'immutable';
import ContentFinder from '../ContentFinder';
import Guid from '../Guid';
import ContentFinder from '../../../helpers/ContentFinder';
import Guid from '../../../helpers/Guid';

class DeleteFigure {
constructor(content) {
Expand Down
6 changes: 6 additions & 0 deletions modules/plugins/youtube/index.js
@@ -1,6 +1,10 @@
import Block from "./YouTube";
import ReturnKey from "./YouTubeReturnKey";
import './YouTube.scss';

// figure
import BspaceKey from '../shared/FigureBspaceKey';
import DeleteKey from '../shared/FigureDeleteKey';
import '../shared/Figure.scss';
import '../shared/FigCaption.scss';

Expand All @@ -11,6 +15,8 @@ const Plugin = {

installKeys(config) {
config.use(ReturnKey, { before: 'return' });
config.use(BspaceKey, { before: 'bspace' });
config.use(DeleteKey, { before: 'delete' });
},
};

Expand Down

0 comments on commit c294985

Please sign in to comment.