Skip to content

Commit 24a8f35

Browse files
authored
Merge pull request #608 from brownplt/horizon
"Sticky" Tables (closes #595)
2 parents 91d2c98 + 3b2ee00 commit 24a8f35

File tree

9 files changed

+156
-24
lines changed

9 files changed

+156
-24
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ everything in `.env` is just an environment variable if you really want to
1010
manage things yourself, but using Heroku tools makes sure you run like things
1111
do in production.
1212

13-
First, get the [Heroku toolbelt](https://toolbelt.heroku.com/).
13+
First, get the [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli).
1414

1515
Then, copy `.env.example` to `.env`. If all you want to do is run Pyret code
1616
and test out the REPL, you only need to edit a few variables. If you want to

package-lock.json

Lines changed: 14 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"author": "Joe Politz",
8989
"license": "Apache-2.0",
9090
"devDependencies": {
91-
"chromedriver": "^134.0.3",
91+
"chromedriver": "^141.0.1",
9292
"selenium-webdriver": "^3.6.0",
9393
"webpack-cli": "^5.1.4"
9494
}

src/web/css/editor.css

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,6 +1612,18 @@ code div {
16121612
#vg-tooltip-element {
16131613
z-index: 15100;
16141614
}
1615+
#vg-tooltip-element.visible {
1616+
font-size: inherit;
1617+
}
1618+
1619+
#vg-tooltip-element.visible table tr td.key {
1620+
color: var(--repl-output);
1621+
padding-top: 0.5em;
1622+
padding-right: 0.5em;
1623+
padding-bottom: 0.5em;
1624+
/* Note: not setting background color, so that we get clearer rows */
1625+
font-weight: var(--th-font-weight);
1626+
}
16151627

16161628
.ui-dialog-titlebar {
16171629
background-color: var(--ui-dialog-title-bg);
@@ -2282,9 +2294,56 @@ table.pyret-table.pyret-matrix {
22822294
border-right-width: 2px;
22832295
}
22842296

2297+
2298+
table.pyret-table { width: 98%; }
22852299
table.pyret-table thead {
22862300
box-shadow: 0px 2px 2px var(--shadow-color);
22872301
}
2302+
table.pyret-table tr { table-layout: fixed; display: table; width: 100%; }
2303+
/* Force tables to be the full height of the viewport, leaving 225px for other chrome */
2304+
table.pyret-table tbody {
2305+
--bgRGB: 200, 210, 220;
2306+
--bg: rgb(var(--bgRGB));
2307+
--bgTrans: rgba(var(--bgRGB), 0);
2308+
2309+
--shadow: rgba(41, 50, 56, 0.5);
2310+
2311+
max-height: calc(100vh - 225px); display: block;
2312+
overflow: auto;
2313+
2314+
background:
2315+
/* Shadow Cover TOP */
2316+
linear-gradient(
2317+
var(--bg) 30%,
2318+
var(--bgTrans)
2319+
) center top,
2320+
2321+
/* Shadow Cover BOTTOM */
2322+
linear-gradient(
2323+
var(--bgTrans),
2324+
var(--bg) 70%
2325+
) center bottom,
2326+
2327+
/* Shadow TOP */
2328+
radial-gradient(
2329+
farthest-side at 50% 0,
2330+
var(--shadow),
2331+
rgba(0, 0, 0, 0)
2332+
) center top,
2333+
2334+
/* Shadow BOTTOM */
2335+
radial-gradient(
2336+
farthest-side at 50% 100%,
2337+
var(--shadow),
2338+
rgba(0, 0, 0, 0)
2339+
) center bottom;
2340+
2341+
background-repeat: no-repeat;
2342+
background-size: 100% 8px, 100% 5px, 100% 5px, 100% 8px;
2343+
background-attachment: local, local, scroll, scroll;
2344+
}
2345+
2346+
22882347
table.pyret-row th {
22892348
box-shadow: 2px 0px 2px var(--shadow-color), -2px 0px 2px var(--shadow-color);
22902349
border: none;

src/web/editor.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,18 @@ <h2>Announcements</h2>
447447
var GIT_BRANCH = "{{ &GIT_BRANCH }}";
448448
</script>
449449

450+
<script>
451+
if (typeof Promise.withResolvers === 'undefined') {
452+
Promise.withResolvers = function () {
453+
let resolve, reject
454+
const promise = new Promise((res, rej) => {
455+
resolve = res
456+
reject = rej
457+
})
458+
return { promise, resolve, reject }
459+
}
460+
}
461+
</script>
450462
<script src="{{ &BASE_URL }}/js/es6-shim.js"></script>
451463
<script src="{{ &BASE_URL }}/js/jquery.min.js"></script>
452464
<script src="{{ &BASE_URL }}/js/jquery-ui.min.js"></script>

src/web/js/beforePyret.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ $(function() {
152152
animationDiv = null;
153153
}
154154
}
155+
let activeEditor = null;
155156
CPO.makeEditor = function(container, options) {
156157
var initial = "";
157158
if (options.hasOwnProperty("initial")) {
@@ -196,8 +197,7 @@ $(function() {
196197
console.log("Using keymap: ", CodeMirror.keyMap.default, "macDefault: ", CodeMirror.keyMap.macDefault, "mac: ", mac);
197198
const modifier = mac ? "Cmd" : "Ctrl";
198199

199-
var cmOptions = {
200-
extraKeys: CodeMirror.normalizeKeyMap({
200+
const extraKeys = {
201201
"Shift-Enter": function(cm) { runFun(cm.getValue()); },
202202
"Shift-Ctrl-Enter": function(cm) { runFun(cm.getValue()); },
203203
"Tab": "indentAuto",
@@ -210,7 +210,21 @@ $(function() {
210210
"Ctrl-Right": "goForwardToken",
211211
[`${modifier}-F`]: "findPersistent",
212212
[`${modifier}-/`]: "toggleComment",
213-
}),
213+
};
214+
if(window.PYRET_IN_VSCODE) {
215+
// Disable undo and redo in vscode, since they mess with the host editor's undo/redo stack
216+
// Oddly, it doesn't seem to work to add these to extraKeys; I have to
217+
// override them in the default keymap
218+
CodeMirror.keyMap.default[`${modifier}-Z`] = false;
219+
CodeMirror.keyMap.default[`Shift-${modifier}-Z`] = false;
220+
CodeMirror.keyMap.default[`${modifier}-Y`] = false;
221+
// Ctrl-U is Undo within a range
222+
CodeMirror.keyMap.default[`${modifier}-U`] = false;
223+
}
224+
225+
var cmOptions = {
226+
keyMap: 'default',
227+
extraKeys: CodeMirror.normalizeKeyMap(extraKeys),
214228
indentUnit: 2,
215229
tabSize: 2,
216230
viewportMargin: Infinity,
@@ -230,6 +244,9 @@ $(function() {
230244
cmOptions = merge(cmOptions, options.cmOptions || {});
231245

232246
var CM = CodeMirror.fromTextArea(textarea[0], cmOptions);
247+
CM.on("focus", () => {
248+
activeEditor = CM;
249+
});
233250

234251
function firstLineIsNamespace() {
235252
const firstline = CM.getLine(0);
@@ -1410,6 +1427,10 @@ $(function() {
14101427

14111428
});
14121429

1430+
window.addEventListener("focus", (e) => {
1431+
if(activeEditor) { activeEditor.focus(); }
1432+
});
1433+
14131434
function makeEvent() {
14141435
const handlers = [];
14151436
function on(handler) {
@@ -1453,15 +1474,20 @@ $(function() {
14531474

14541475
let initialState = params["get"]["initialState"];
14551476

1477+
window.PYRET_IS_EMBEDDED = false;
1478+
window.PYRET_IN_VSCODE = false;
14561479
if (typeof acquireVsCodeApi === "function") {
14571480
window.MESSAGES = makeEvents({
14581481
CPO: CPO,
14591482
sendPort: acquireVsCodeApi(),
14601483
receivePort: window,
14611484
initialState
14621485
});
1486+
window.PYRET_IS_EMBEDDED = true;
1487+
window.PYRET_IN_VSCODE = true;
14631488
}
14641489
else if((window.parent && (window.parent !== window))) {
14651490
window.MESSAGES = makeEvents({ CPO: CPO, sendPort: window.parent, receivePort: window, initialState });
1491+
window.PYRET_IS_EMBEDDED = true;
14661492
}
14671493
});

src/web/js/cpo-main.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,11 @@
105105
else if(window.IMAGE_PROXY_BYPASS) {
106106
return s;
107107
}
108+
/*
108109
else if(a.hostname === "drive.google.com" && a.pathname === "/uc") {
109110
return s;
110111
}
112+
*/
111113
else {
112114
return window.APP_BASE_URL + "/downloadImg?" + s;
113115
}
@@ -666,11 +668,17 @@
666668

667669
// save
668670
// On Mac mod ends up mapping to command+s whereas on Windows and Linux it maps to ctrl+s.
669-
Mousetrap.bindGlobal('mod+s', function(e) {
670-
CPO.save();
671-
e.stopImmediatePropagation();
672-
e.preventDefault();
673-
});
671+
// Saving has a special condition: when embedded we want the Ctrl-S to
672+
// propagate up. We could fire a special “save” event, but for contexts
673+
// like VScode it is nice to have the “real” Cmd-S event fire to get
674+
// good default behavior
675+
if(!PYRET_IS_EMBEDDED) {
676+
Mousetrap.bindGlobal('mod+s', function(e) {
677+
CPO.save();
678+
e.stopImmediatePropagation();
679+
e.preventDefault();
680+
});
681+
}
674682

675683
// resize, Toggle sizing of the editor window between 50% and last resize
676684
Mousetrap.bindGlobal('ctrl+m', function(e){

src/web/js/google-apis/picker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ FilePicker.prototype.initOpen = function(picker) {
103103
* A Picker View which displays images users may load.
104104
*/
105105
var imageView = new picker.View(picker.ViewId.DOCS);
106-
imageView.setMimeTypes("image/png,image/jpeg,image/jpg,image/gif");
106+
imageView.setMimeTypes("image/png,image/jpeg,image/jpg,image/gif,image/webp");
107107

108108
var allViews = {
109109
imageView: imageView,

test/number.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
var assert = require("assert");
2+
var tester = require("../test-util/util.js");
3+
var webdriver = require("selenium-webdriver");
4+
5+
describe("Numbers at the REPL", function() {
6+
beforeEach(tester.setup);
7+
afterEach(tester.teardown);
8+
9+
it("should render toggle-able numbers", function(done) {
10+
this.timeout(80000);
11+
var self = this;
12+
this.browser.get(this.base + "/editor");
13+
this.browser.wait(function() { return tester.pyretLoaded(self.browser); });
14+
tester.evalPyret(this.browser, "1/7");
15+
this.browser.wait(function() {
16+
return self.browser.findElements(webdriver.By.className("rationalRepeat")).then((els) => els.length > 0);
17+
});
18+
this.browser.findElements(webdriver.By.className("rationalRepeat")).then(function(elements) {
19+
elements[0].getAttribute("innerText").then(function(text) {
20+
assert.equal(text, "142857");
21+
});
22+
});
23+
this.browser.call(done);
24+
25+
});
26+
});

0 commit comments

Comments
 (0)