Skip to content

Commit

Permalink
revert truncate results
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbicodes committed Jun 28, 2023
1 parent 205f7a3 commit 6f49085
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 215 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Alpha. Certainly contains bugs. There is a [live demo](https://bobbicodes.github
- ✅ Test published package
- ✅ Handle errors
- ✅ Pretty-print eval result
- Truncate very long eval result
- [ ] Truncate very long eval result
- [ ] Handle infinite loops

## Run demo locally
Expand Down
403 changes: 201 additions & 202 deletions dist/assets/index-53d4dbe5.js → dist/assets/index-1337c271.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="icon" type="image/svg+xml" href="/lang-clojure-eval/assets/vite-4a748afd.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
<script type="module" crossorigin src="/lang-clojure-eval/assets/index-53d4dbe5.js"></script>
<script type="module" crossorigin src="/lang-clojure-eval/assets/index-1337c271.js"></script>
<link rel="stylesheet" href="/lang-clojure-eval/assets/index-b488241e.css">
</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lang-clojure-eval",
"version": "0.0.13",
"version": "0.0.14",
"author": "Bobbi Towers <[email protected]>",
"description": "Lezer-based Clojure Codemirror 6 extension with live evaluation",
"main": "dist/index.cjs",
Expand Down
13 changes: 3 additions & 10 deletions src/eval-region.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,6 @@ function updateEditor(view, text, pos) {
})
}

function splitResult(s) {
if (s.length > 100) {
return "\n" + s.substring(0, 100) + "..." + s.substring(s.length -2)
}
return s
}

function tryEval(ctx, s) {
try {
return evalString(ctx, s)
Expand All @@ -153,7 +146,7 @@ function evalAtCursor(view) {
posBeforeEval = view.state.selection.main.head
const codeBeforeCursor = codeBeforeEval.slice(0, posBeforeEval)
const codeAfterCursor = codeBeforeEval.slice(posBeforeEval, codeBeforeEval.length)
evalResult = splitResult(tryEval(ctx, cursorNodeString(view.state)))
evalResult = tryEval(ctx, cursorNodeString(view.state))
const codeWithResult = codeBeforeCursor + " => " + evalResult + " " + codeAfterCursor
updateEditor(view, codeWithResult, posBeforeEval)
view.dispatch({selection: {anchor: posBeforeEval, head: posBeforeEval}})
Expand All @@ -174,15 +167,15 @@ function evalTopLevel(view) {
codeBeforeEval = doc
const codeBeforeFormEnd = codeBeforeEval.slice(0, posAtFormEnd)
const codeAfterFormEnd = codeBeforeEval.slice(posAtFormEnd, codeBeforeEval.length)
evalResult = splitResult(tryEval(ctx, topLevelString(view.state)))
evalResult = tryEval(ctx, topLevelString(view.state))
const codeWithResult = codeBeforeFormEnd + " => " + evalResult + " " + codeAfterFormEnd
updateEditor(view, codeWithResult, posBeforeEval)
return true
}

function evalCell(view) {
const doc = view.state.doc.toString()
evalResult = splitResult(tryEval(ctx, view.state.doc.text.join(" ")))
evalResult = tryEval(ctx, view.state.doc.text.join(" "))
const codeWithResult = doc + "\n" + " => " + evalResult
updateEditor(view, codeWithResult, posBeforeEval)
//console.log("evalCell>", evalString(ctx, view.state.doc.text.join(" ")))
Expand Down

0 comments on commit 6f49085

Please sign in to comment.