Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
43318b72
Commit
43318b72
authored
Mar 27, 2012
by
Bridger Maxwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing deletion / insertion bugs and inconsistencies
parent
952b7549
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
25 deletions
+44
-25
static/js/CodeMirror/codemirror.js
+35
-16
static/js/CodeMirror/mitx_markdown.js
+4
-4
templates/simplewiki_edit.html
+5
-5
No files found.
static/js/CodeMirror/codemirror.js
View file @
43318b72
...
...
@@ -616,6 +616,24 @@ var CodeMirror = (function() {
// Afterwards, set the selection to selFrom, selTo.
function
updateLines
(
from
,
to
,
newText
,
selFrom
,
selTo
)
{
if
(
suppressEdits
)
return
;
if
(
from
.
ch
>
0
&&
newText
[
0
]
!=
''
&&
getLine
(
from
.
line
).
isWidgetBlock
)
{
newText
.
unshift
(
''
);
var
widgetLine
=
getLine
(
from
.
line
);
function
moveSel
(
sel
)
{
if
(
sel
.
line
==
from
.
line
&&
sel
.
ch
>
0
){
return
{
line
:
sel
.
line
+
1
,
ch
:
sel
.
ch
-
widgetLine
.
text
.
length
};
}
else
if
(
sel
.
line
>
from
.
line
)
{
return
{
line
:
sel
.
line
+
1
,
ch
:
sel
.
ch
};
}
}
selFrom
=
moveSel
(
selFrom
,
widgetLine
);
selTo
=
moveSel
(
selTo
,
widgetLine
);
}
if
(
to
.
ch
==
0
&&
newText
[
newText
.
length
-
1
]
!=
''
&&
getLine
(
to
.
line
).
isWidgetBlock
)
{
newText
.
push
(
''
);
}
if
(
history
)
{
var
old
=
[];
doc
.
iter
(
from
.
line
,
to
.
line
+
1
,
function
(
line
)
{
old
.
push
(
line
.
text
);
});
...
...
@@ -726,7 +744,6 @@ var CodeMirror = (function() {
if
(
guess
!=
line
.
height
)
updateLineHeight
(
line
,
guess
);
});
}
else
{
//TODO: update height here for widget blocks
doc
.
iter
(
from
.
line
,
from
.
line
+
newText
.
length
,
function
(
line
)
{
var
l
=
line
.
text
;
if
(
l
.
length
>
maxLineLength
)
{
...
...
@@ -779,23 +796,11 @@ var CodeMirror = (function() {
return
end
;
}
function
replaceSelection
(
code
,
collapse
)
{
var
reposition
=
false
;
if
(
code
.
length
>
0
)
{
var
fromLine
=
getLine
(
sel
.
from
.
line
),
toLine
=
getLine
(
sel
.
to
.
line
);
if
(
fromLine
.
isWidgetBlock
&&
sel
.
from
.
ch
==
fromLine
.
text
.
length
)
{
code
=
"
\
n"
+
code
;
}
else
if
(
toLine
.
isWidgetBlock
&&
sel
.
to
.
ch
==
0
)
{
code
=
code
+
"
\
n"
;
reposition
=
true
;
}
}
replaceRange1
(
splitLines
(
code
),
sel
.
from
,
sel
.
to
,
function
(
end
)
{
if
(
collapse
==
"end"
)
return
{
from
:
end
,
to
:
end
};
else
if
(
collapse
==
"start"
)
return
{
from
:
sel
.
from
,
to
:
sel
.
from
};
else
return
{
from
:
sel
.
from
,
to
:
end
};
});
if
(
reposition
)
moveH
(
-
1
,
"char"
);
}
function
replaceRange1
(
code
,
from
,
to
,
computeSel
)
{
var
endch
=
code
.
length
==
1
?
code
[
0
].
length
+
from
.
ch
:
code
[
code
.
length
-
1
].
length
;
...
...
@@ -1266,9 +1271,19 @@ var CodeMirror = (function() {
setCursor
(
pos
.
line
,
pos
.
ch
,
true
);
}
function
deleteH
(
dir
,
unit
)
{
if
(
!
posEq
(
sel
.
from
,
sel
.
to
))
replaceRange
(
""
,
sel
.
from
,
sel
.
to
);
else
if
(
dir
<
0
)
replaceRange
(
""
,
findPosH
(
dir
,
unit
),
sel
.
to
);
else
replaceRange
(
""
,
sel
.
from
,
findPosH
(
dir
,
unit
));
var
from
=
sel
.
from
;
var
to
=
sel
.
to
;
if
(
posEq
(
sel
.
from
,
sel
.
to
))
{
if
(
dir
<
0
)
{
from
=
findPosH
(
dir
,
unit
);
if
(
getLine
(
from
.
line
).
isWidgetBlock
)
from
.
ch
=
0
;
}
else
{
to
=
findPosH
(
dir
,
unit
);
if
(
getLine
(
to
.
line
).
isWidgetBlock
)
to
.
ch
=
getLine
(
to
.
line
).
text
.
length
;
}
}
replaceRange
(
""
,
from
,
to
);
userSelChange
=
true
;
}
var
goalColumn
=
null
;
...
...
@@ -1554,6 +1569,10 @@ var CodeMirror = (function() {
var
tempId
=
Math
.
floor
(
Math
.
random
()
*
0xffffff
).
toString
(
16
);
function
measureLine
(
line
,
ch
)
{
if
(
ch
==
0
)
return
{
top
:
0
,
left
:
0
};
if
(
line
.
isWidgetBlock
)
{
var
size
=
line
.
styles
[
1
].
size
(
line
.
text
);
return
{
top
:
-
1
,
left
:
size
.
width
};
}
var
extra
=
""
;
// Include extra text at the end to make sure the measured line is wrapped in the right way.
if
(
options
.
lineWrapping
)
{
...
...
static/js/CodeMirror/mitx_markdown.js
View file @
43318b72
...
...
@@ -2,7 +2,7 @@ $(function(){
$
(
document
).
ready
(
function
()
{
$
(
"a[rel*=leanModal]"
).
leanModal
();
$
(
"body"
).
append
(
'<div id="circuit_editor" class="leanModal_box" style="z-index: 11000; left: 50%; margin-left: -250px; position: absolute; top: 100px; opacity: 1; "><div align="center"> <input class="schematic" height="
300" width="40
0" id="schematic_editor" name="schematic" type="hidden" value=""/> <button type="button" id="circuit_save_btn">save</button></div></div>'
);
$
(
"body"
).
append
(
'<div id="circuit_editor" class="leanModal_box" style="z-index: 11000; left: 50%; margin-left: -250px; position: absolute; top: 100px; opacity: 1; "><div align="center"> <input class="schematic" height="
150" width="15
0" id="schematic_editor" name="schematic" type="hidden" value=""/> <button type="button" id="circuit_save_btn">save</button></div></div>'
);
//This is the editor that pops up as a modal
var
editorCircuit
=
$
(
"#schematic_editor"
).
get
(
0
);
...
...
@@ -65,13 +65,13 @@ CodeMirror.defineMode("mitx_markdown", function(cmCfg, modeCfg) {
//TODO: We need real html escaping here
circuit_value
=
CodeMirror
.
htmlEscape
(
circuit_value
);
// circuit_value.replace("\"", "'");
var
html
=
"<a href='#circuit_editor' rel='leanModal' class='schematic_open' style='
width:400px; '><input type='hidden' parts='' value='"
+
circuit_value
+
"
' analyses='' class='schematic ctrls'/></a>"
;
var
html
=
"<a href='#circuit_editor' rel='leanModal' class='schematic_open' style='
display:inline-block;'>"
+
"<input type='hidden' parts='' value='"
+
circuit_value
+
"' width='150' height='150
' analyses='' class='schematic ctrls'/></a>"
;
return
html
;
},
size
:
function
(
text
)
{
return
{
width
:
400
,
height
:
302
};
return
{
width
:
150
,
height
:
154
};
},
callback
:
function
(
node
,
line
)
{
update_schematics
();
...
...
templates/simplewiki_edit.html
View file @
43318b72
...
...
@@ -45,11 +45,11 @@
//Store the inital contents so we can compare for unsaved changes
var
initial_contents
=
editor
.
getValue
();
window
.
onbeforeunload
=
function
askConfirm
()
{
//Warn the user before they navigate away
if
(
editor
.
getValue
()
!=
initial_contents
)
{
return
"You have made changes to the article that have not been saved yet."
;
}
};
//
window.onbeforeunload = function askConfirm() { //Warn the user before they navigate away
//
if ( editor.getValue() != initial_contents ) {
//
return "You have made changes to the article that have not been saved yet.";
//
}
//
};
$
(
"#submit_edit"
).
click
(
function
()
{
initial_contents
=
editor
.
getValue
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment