Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New files (NavBar) #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 99 additions & 28 deletions brick-editor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global require, module, editor, editorState, blockDict, monaco */

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to add your new functions into this list to fix the lint.

var BLOCK_DELETE_TYPES = [
"IfStatement",
"IfStatement",
"ForStatement",
"FunctionDeclaration",
"WhileStatement",
Expand Down Expand Up @@ -183,8 +183,8 @@ function onPointBackspace() {
}
} else if (spansProtectedPunctuation(buffer, ast, [oneBack, cursor])) {
// ignore the backspace if it's something important
// flash editor screen
flash();
// flash editor screen
flash();
} else {
charBackspaceBranch(buffer, cursor);
}
Expand Down Expand Up @@ -234,15 +234,15 @@ function onPointDelete() {
}
} else if (spansProtectedPunctuation(buffer, ast, [cursor, oneAhead])) {
// ignore the delete if it's something important
// flash editor screen
flash();
// flash editor screen
flash();
} else {
charDeleteBranch(buffer, cursor);
}
} else if (cursor.lineNumber == editorState.cursor.lineNumber) { // if unparsable but on same line
// if inside parentheses when became unparsable
// if inside parentheses when became unparsable
if (editorState.openParenthesis && editorState.closeParenthesis) {
if (positionFromEnd(buffer, cursor) - 1 == editorState.closeParenthesis) { // if directly to left of )
if (positionFromEnd(buffer, cursor) - 1 == editorState.closeParenthesis) { // if directly to left of )
// ignore delete if parenthesis
flash();
} else if (positionFromStart(buffer, cursor) <= editorState.openParenthesis || positionFromEnd(buffer, cursor) <= editorState.closeParenthesis) { // if left of ( or right of )
Expand Down Expand Up @@ -287,32 +287,103 @@ function onRangeDelete() {
unhighlight();
} else {
highlight(node.loc.start.line, node.loc.start.column, node.loc.end.line, node.loc.end.column);
}
}
}
updateEditorState();
}

/**
/**
* Set value of editor using executeEdits to preserve undo stack
*
* @param {string} newBuffer - String replacing oldBuffer.
* @returns {undefined}
*/
function setValue(newBuffer) {
// get range of editor model
// get range of editor model
var range = editor.getModel().getFullModelRange();
// call execute edits on the editor
// call execute edits on the editor
editor.executeEdits(editor.getValue(), [{ identifier: "insert", range: range, text: newBuffer }]);
}

/**
/**
* Resets the buffer value to the last correct parsed state
*
* @returns {undefined}
*/
function resetToParsed() { // eslint-disable-line no-unused-vars
setValue(editorState.parsableText);
}
}

/**
* Undo function
* @returns {undefined}
*/
function buttonUndo(){
setValue(editor.getModel().undo());
}

/**
* Redo function
*
* @returns {undefined}
*/
function buttonRedo(){
setValue(editor.getModel().redo());
}

/**
* Zoom in function
*
* @returns {undefined}
*/
function buttonZoomIn(){
editor.updateOptions({fontSize: 30 });
}

/**
* Zoom out function
*
* @returns {undefined}
*/
function buttonZoomOut(){
editor.updateOptions({fontSize: 10 });
}

/**
* Default zoom function
*
* @returns {undefined}
*/
function buttonDefaultZoom(){
editor.updateOptions({fontSize: 14 });
}

/**
* Copy function
*
* @returns {undefined}
*/
function buttonCopy(){
document.execCommand('copy', false);
}

/**
* Cut function
*
* @returns {undefined}
*/
function buttonCut(){
document.execCommand('Cut', false);
}

/**
* Paste function
*
* @returns {undefined}
*/
function buttonPaste(){
document.execCommand('Paste', data);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused by this line - what's data?

}


// EDITOR INTERFACE CODE
Expand Down Expand Up @@ -408,16 +479,16 @@ function unhighlight() {
highlighted = false;
}

/**
* Flashes the editor background for 100 ms
*
* @returns {undefined}
/**
* Flashes the editor background for 100 ms
*
* @returns {undefined}
*/
function flash() {
monaco.editor.setTheme("flash");
setTimeout(function () { monaco.editor.setTheme("normal"); }, 100);

}
}

/**
* Highlights from opening parenthesis to closed parenthesis, inclusive
Expand Down Expand Up @@ -904,7 +975,7 @@ function getSurroundingProtectedBrace(buffer, ast, cursor) {

/**
* Split a string into sections delimited by Cursors.
*
*
* @param {string} buffer - A string of text from the editor.
* @param {[Cursor]} cursors - Non-empty list of cursors.
* @returns {[string]} - List of sections of the original string.
Expand Down Expand Up @@ -962,11 +1033,11 @@ function onDidChangeCursorSelection(e) { // eslint-disable-line no-unused-vars
var selection = e.selection;
console.log(" [" +
selection.startLineNumber
+ ":" +
+ ":" +
selection.startColumn
+ ", " +
+ ", " +
selection.endLineNumber
+ ":" +
+ ":" +
selection.endColumn
+ "]"
);
Expand Down Expand Up @@ -1053,7 +1124,7 @@ function updateEditorState() {
editorState.cursor = getCursor();
editorState.sections = splitAtCursors(buffer, [editorState.cursor]);
}
} else {
} else {
editorState.parsable = false;
// if on same line
if (cursor.lineNumber == editorState.cursor.lineNumber) {
Expand Down Expand Up @@ -1093,12 +1164,12 @@ function positionFromStart(buffer, cursor) {
* @returns {string} Position of cursor from end of buffer
*/
function positionFromEnd(buffer, cursor) {
var splitBuffer = buffer.split("\n");
var lastPart = splitBuffer.slice(cursor.lineNumber);
var sameLine = splitBuffer.slice(cursor.lineNumber - 1, cursor.lineNumber).join("");
sameLine = sameLine.split("");
var splitBuffer = buffer.split("\n");
var lastPart = splitBuffer.slice(cursor.lineNumber);
var sameLine = splitBuffer.slice(cursor.lineNumber - 1, cursor.lineNumber).join("");
sameLine = sameLine.split("");
sameLine = sameLine.slice(cursor.column).join("");
lastPart.unshift(sameLine);
lastPart.unshift(sameLine);

return lastPart.join("").length;
}
Expand Down
9 changes: 9 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@
addBlocksHTML();
};
</script>
<button id="genericButton" onclick="buttonUndo()">UNDO</button>
<button id="genericButton" onclick="buttonRedo()">REDO</button>
<button id="genericButton" onclick="buttonDefaultZoom()">DEFAULT ZOOM</button>
<button id="genericButton" onclick="buttonZoomIn()">ZOOM IN</button>
<button id="genericButton" onclick="buttonZoomOut()">ZOOM OUT</button>
<button id="genericButton" onclick="buttonCopy()">COPY</button>
<button id="genericButton" onclick="buttonCut()">CUT</button>
<button id="genericButton" onclick="buttonPaste()">PASTE</button>
<br>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably mean class="genericButton" and not id.

</head>

<body>
Expand Down
29 changes: 27 additions & 2 deletions stylesheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,30 @@ body {
#parseButton:disabled {
background-color: grey;
color: white;
cursor: default;
}
cursor: not-allowed;
}

#genericButton {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to ".genericButton" to make it with with classes

border: solid black 1px;
background-color: red;
color: white;
font-weight: 600;
padding: 10px;
text-align: center;
font-size: 16px;
border-radius: 5px;
margin: 0px auto;
float: left;
cursor: pointer;
transition-duration: 0.4s;
}

#genericButton:hover{
background-color: forestgreen;
}

#genericButton:active{
background-color: blue;
transform: translateY(4px);
}