Skip to content

Commit

Permalink
more work on #335 - fix webpack sound loading, add WRAP sound for sea…
Browse files Browse the repository at this point in the history
…rch, and expose cm.getOption()
  • Loading branch information
Emmanuel Schanzer committed Mar 1, 2021
1 parent 3b1e28b commit 6526268
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 13 deletions.
1 change: 0 additions & 1 deletion spec/api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ describe("when testing CM apis,", function () {
expect(()=>this.cmb.findPosH(true)).toThrow();
expect(()=>this.cmb.findPosV(true)).toThrow();
expect(()=>this.cmb.getExtending(true)).toThrow();
expect(()=>this.cmb.getOption(true)).toThrow();
expect(()=>this.cmb.indentLine(true)).toThrow();
expect(()=>this.cmb.off(true)).toThrow();
expect(()=>this.cmb.on(true)).toThrow();
Expand Down
1 change: 0 additions & 1 deletion src/components/Node.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import SHARED from '../shared';
import {DragNodeSource, DropNodeTarget} from '../dnd';
import classNames from 'classnames';
import {store} from '../store';
import {playSound, BEEP} from '../sound';

// TODO(Oak): make sure that all use of node.<something> is valid
// since it might be cached and outdated
Expand Down
7 changes: 5 additions & 2 deletions src/sound.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const beepSound = require('./beep.wav');
import beepSound from './beep.wav';
export const BEEP = new Audio(beepSound);
BEEP.crossorigin = "anonymous";
export const WRAP = BEEP; // eventually use a different sound for this

import wrapSound from './wrap.mp3';
export const WRAP = new Audio(wrapSound);
WRAP.crossorigin = "anonymous";

export function playSound(sound) {
sound.pause();
Expand Down
13 changes: 9 additions & 4 deletions src/ui/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import PropTypes from 'prop-types/prop-types';
import Modal from 'react-modal';
import {Tab, Tabs, TabList, TabPanel} from 'react-tabs';
import 'react-tabs/style/react-tabs.less';
import {say} from '../utils';
import {say, getBeginCursor, getEndCursor} from '../utils';
import {playSound, WRAP} from '../sound';

export default (Editor, searchModes) => {
const settings = searchModes.reduce((acc, searchMode, i) => {
Expand Down Expand Up @@ -51,12 +52,13 @@ export default (Editor, searchModes) => {
this.callback();
}

handleSearch = (forward, cmbState) => {
handleSearch = (forward, cmbState, overrideCur) => {
console.log(overrideCur);
if(this.state.searchEngine == null) {
say("No search setting have been selected.");
return;
}
var searchFrom = this.state.cursor, result;
var searchFrom = overrideCur || this.state.cursor, result;
// keep searching until we find an unfocused node, or we run out of results
while((result = searchModes[this.state.searchEngine].search(
searchFrom,
Expand All @@ -72,7 +74,10 @@ export default (Editor, searchModes) => {
this.setState({cursor});
return node;
} else {
return null;
if(overrideCur) return null; // if there's no wrapped match, give up
playSound(WRAP);
const wrappedStart = (forward? getBeginCursor : getEndCursor)(this.cm);
return this.handleSearch(forward, cmbState, wrappedStart)
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ export function getLastVisibleNode(state) {
export function withDefaults(obj, def) {
return {...def, ...obj};
}
/*

export function getBeginCursor(cm) {
return CodeMirror.Pos(cm, 0);
return CodeMirror.Pos(0, 0);
}

export function getEndCursor(cm) {
Expand All @@ -173,7 +173,7 @@ export function getEndCursor(cm) {
cm.getLine(cm.lastLine()).length
);
}
*/

export function posWithinNode(pos, node) {
return (poscmp(node.from, pos) <= 0) && (poscmp(node.to, pos) > 0)
|| (poscmp(node.from, pos) < 0) && (poscmp(node.to, pos) >= 0);
Expand Down
Binary file added src/wrap.mp3
Binary file not shown.
4 changes: 2 additions & 2 deletions webpack/base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ module.exports = function(config) {
var plugins = [];
var rules = [
{
test:/.woff$|.woff2.png$|.jpg$|.jpeg$|.gif$|.svg$|.wav$/,
test:/.woff$|.woff2.png$|.jpg$|.jpeg$|.gif$|.svg$/,
use: [{ loader: "url-loader", options: { limit: 10000, esModule: false } }]
},
{
test:/.ttf$|.eot$/,
test:/.ttf$|.eot$|.wav$|.mp3$/,
use: [{loader: "file-loader"}]
},
{
Expand Down

0 comments on commit 6526268

Please sign in to comment.