Skip to content

Commit a7e9ec2

Browse files
authored
Merge pull request #73 from CSchank/bugfix
Bugfix: left arrow to reset the tape
2 parents 4a3db80 + f2997f5 commit a7e9ec2

File tree

6 files changed

+83
-65
lines changed

6 files changed

+83
-65
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ jobs:
2929
stages:
3030
- test
3131
- name: deploy
32-
if: "(branch = master) AND (type = push)"
32+
if: "(branch = master) AND (tag IS present)"

elm.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"elm-version": "0.19.0",
77
"dependencies": {
88
"direct": {
9-
"MacCASOutreach/graphicsvg": "6.1.0",
9+
"MacCASOutreach/graphicsvg": "5.1.0",
1010
"billstclair/elm-sha256": "1.0.8",
1111
"elm/browser": "1.0.1",
1212
"elm/core": "1.0.2",

src/Building.elm

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module Building exposing (Model, Msg(..), PersistentModel(..), editingButtons, init, initPModel, onEnter, onExit, subscriptions, update, updateArrowPos, updateStatePos, view)
22

33
import Browser.Events
4+
import Debug
45
import Dict exposing (Dict)
56
import Environment exposing (Environment)
67
import GraphicSVG exposing (..)
@@ -33,7 +34,7 @@ type Msg
3334
| SaveStateName StateID String
3435
| SaveTransitionName TransitionID String
3536
| AddState ( Float, Float )
36-
| KeyPressed Int
37+
| KeyPressed String
3738
| ToggleSnap
3839
| ChangeSnap Int
3940
| NoOp
@@ -42,7 +43,7 @@ type Msg
4243
subscriptions : Model -> Sub Msg
4344
subscriptions model =
4445
Sub.batch
45-
[ Browser.Events.onKeyDown (D.map KeyPressed (D.field "keyCode" D.int))
46+
[ Browser.Events.onKeyDown (D.map KeyPressed (D.field "key" D.string))
4647
]
4748

4849

@@ -425,7 +426,7 @@ update env msg ( model, pModel, sModel ) =
425426
( ( { model | machineState = Regular }, pModel, sModel ), False, Cmd.none )
426427

427428
KeyPressed k ->
428-
if k == 13 then
429+
if k == "Enter" then
429430
--pressed enter
430431
case model.machineState of
431432
EditingStateLabel sId newLbl ->
@@ -463,8 +464,7 @@ update env msg ( model, pModel, sModel ) =
463464
_ ->
464465
( ( model, pModel, sModel ), False, Cmd.none )
465466

466-
else if k == 68 then
467-
--pressed delete
467+
else if k == "d" then
468468
case model.machineState of
469469
SelectedState stId ->
470470
let
@@ -526,14 +526,13 @@ update env msg ( model, pModel, sModel ) =
526526
_ ->
527527
( ( model, pModel, sModel ), False, Cmd.none )
528528

529-
else if k == 71 then
530-
--pressed G
529+
else if k == "g" then
531530
( ( model, pModel, sModel ), False, sendMsg ToggleSnap )
532531

533532
else
534533
case model.machineState of
535534
SelectedState sId ->
536-
if k == 70 then
535+
if k == "f" then
537536
let
538537
newMachine =
539538
{ oldMachine

src/Machine.elm

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -752,15 +752,18 @@ renderStates currentStates machine model env =
752752

753753
_ ->
754754
group []
755-
, rect 25 18
756-
|> filled blank
757755
]
758756
|> move (getPos sId)
759-
|> (if not env.holdingShift then
760-
notifyMouseDownAt (StartDragging sId)
757+
|> (case model of
758+
EditingStateLabel _ _ ->
759+
identity
761760

762-
else
763-
notifyTap (TapState sId)
761+
_ ->
762+
if not env.holdingShift then
763+
notifyMouseDownAt (StartDragging sId)
764+
765+
else
766+
notifyTap (TapState sId)
764767
)
765768
)
766769
stateList

src/Main.elm

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ type Msg
3131
= BMsg Building.Msg
3232
| SMsg Simulating.Msg
3333
| EMsg Exporting.Msg
34-
| KeyPressed Int
35-
| KeyReleased Int
34+
| KeyPressed String
35+
| KeyReleased String
3636
| WindowSize ( Int, Int )
3737
| UrlChange Url
3838
| UrlRequest UrlRequest
@@ -94,8 +94,8 @@ main =
9494
\model ->
9595
Sub.batch
9696
[ Browser.Events.onResize (\w h -> WindowSize ( w, h ))
97-
, Browser.Events.onKeyDown (D.map KeyPressed (D.field "keyCode" D.int))
98-
, Browser.Events.onKeyUp (D.map KeyReleased (D.field "keyCode" D.int))
97+
, Browser.Events.onKeyDown (D.map KeyPressed (D.field "key" D.string))
98+
, Browser.Events.onKeyUp (D.map KeyReleased (D.field "key" D.string))
9999
, Browser.Events.onVisibilityChange VisibilityChanged
100100
, case model.appModel.present.appState of
101101
Building m ->
@@ -228,30 +228,30 @@ update msg model =
228228
( model, Cmd.none )
229229

230230
KeyReleased k ->
231-
if k == 16 then
231+
if k == "Shift" then
232232
( { model | environment = { oldEnvironment | holdingShift = False } }, Cmd.none )
233233

234-
else if k == 91 then
234+
else if k == "Meta" then
235235
( { model | environment = { oldEnvironment | holdingMeta = False } }, Cmd.none )
236236

237-
else if k == 17 then
237+
else if k == "Control" then
238238
( { model | environment = { oldEnvironment | holdingControl = False } }, Cmd.none )
239239

240240
else
241241
( model, Cmd.none )
242242

243243
KeyPressed k ->
244-
if k == 16 then
244+
if k == "Shift" then
245245
( { model | environment = { oldEnvironment | holdingShift = True } }, Cmd.none )
246246

247-
else if k == 89 {- y -} || k == 90 {- z -} then
247+
else if k == "y" || k == "z" then
248248
let
249249
doUndo =
250-
(oldEnvironment.holdingControl || oldEnvironment.holdingMeta) && k == 90
250+
(oldEnvironment.holdingControl || oldEnvironment.holdingMeta) && k == "z"
251251

252252
doRedo =
253-
(oldEnvironment.holdingControl && k == 89)
254-
|| (oldEnvironment.holdingMeta && oldEnvironment.holdingShift && k == 90)
253+
(oldEnvironment.holdingControl && k == "y")
254+
|| (oldEnvironment.holdingMeta && oldEnvironment.holdingShift && k == "z")
255255
in
256256
( { model
257257
| appModel =
@@ -267,11 +267,11 @@ update msg model =
267267
, Cmd.none
268268
)
269269

270-
else if k == 91 then
270+
else if k == "Meta" then
271271
--pressed meta key
272272
( { model | environment = { oldEnvironment | holdingMeta = True } }, Cmd.none )
273273

274-
else if k == 17 then
274+
else if k == "Control" then
275275
--pressed control
276276
( { model | environment = { oldEnvironment | holdingControl = True } }, Cmd.none )
277277
{- else if k == 66 then

src/Simulating.elm

Lines changed: 51 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module Simulating exposing (HoverError, InputTape, Model(..), Msg(..), Persisten
22

33
import Array exposing (Array)
44
import Browser.Events
5+
import Debug
56
import Dict exposing (Dict)
67
import Environment exposing (Environment)
78
import Error exposing (..)
@@ -17,7 +18,7 @@ import Tuple exposing (first, second)
1718

1819
subscriptions : Model -> Sub Msg
1920
subscriptions model =
20-
Browser.Events.onKeyDown (D.map KeyPressed (D.field "keyCode" D.int))
21+
Browser.Events.onKeyDown (D.map KeyPressed (D.field "key" D.string))
2122

2223

2324
type alias PersistentModel =
@@ -51,7 +52,7 @@ type Msg
5152
| AddNewTape
5253
| ChangeTape Int
5354
| ToggleStart StateID
54-
| KeyPressed Int
55+
| KeyPressed String
5556
| ChangeMachine MachineType
5657
| MachineMsg Machine.Msg
5758
| HoverErrorEnter Int
@@ -166,7 +167,17 @@ renderTape model input tapeSt tapeId selectedId inputAt showButtons =
166167
, latex (xpad * 0.9) (xpad * 0.7) "white" st AlignCentre
167168
|> move ( 0, 10.25 )
168169
]
169-
|> move ( toFloat n * xpad, 0 )
170+
|> move
171+
( toFloat n
172+
* xpad
173+
+ (if not showButtons then
174+
xpad / 2
175+
176+
else
177+
0
178+
)
179+
, 0
180+
)
170181
|> notifyTap (ChangeTape tapeId)
171182
)
172183
input
@@ -325,17 +336,15 @@ update env msg ( model, pModel, sModel ) =
325336
( ( Default tId -1 Nothing {- ??? -}, { pModel | currentStates = epsTrans oldMachine.transitionNames oldMachine.delta oldMachine.start }, sModel ), False, Cmd.none )
326337

327338
KeyPressed k ->
328-
if k == 13 then
329-
--pressed enter
339+
if k == "Enter" then
330340
case model of
331341
Editing tId ->
332342
( ( Default tId -1 Nothing, { pModel | currentStates = epsTrans oldMachine.transitionNames oldMachine.delta oldMachine.start }, sModel ), True, Cmd.none )
333343

334344
_ ->
335345
( ( model, pModel, sModel ), False, Cmd.none )
336346

337-
else if k == 8 then
338-
--pressed delete
347+
else if k == "Backspace" || k == "ArrowLeft" then
339348
case model of
340349
Editing tapeId ->
341350
let
@@ -366,97 +375,104 @@ update env msg ( model, pModel, sModel ) =
366375
_ ->
367376
( ( model, pModel, sModel ), False, Cmd.none )
368377

369-
else if k == 39 then
370-
--right arrow key
378+
else if k == "ArrowRight" then
371379
case model of
372380
Default _ _ _ ->
373381
( ( model, pModel, sModel ), False, Task.perform identity (Task.succeed <| Step) )
374382

375383
_ ->
376384
( ( model, pModel, sModel ), False, Cmd.none )
377385

386+
else if k == "ArrowLeft" then
387+
case model of
388+
Default tId _ hErr ->
389+
( ( Default tId -1 hErr, { pModel | currentStates = sModel.machine.start }, sModel ), False, Cmd.none )
390+
391+
_ ->
392+
( ( model, pModel, sModel ), False, Cmd.none )
393+
378394
else
379395
case model of
380396
Editing tapeId ->
381397
let
382398
charCode =
383399
case k of
384-
65 ->
400+
"a" ->
385401
0
386402

387-
83 ->
403+
"s" ->
388404
1
389405

390-
68 ->
406+
"d" ->
391407
2
392408

393-
70 ->
409+
"f" ->
394410
3
395411

396-
71 ->
412+
"g" ->
397413
4
398414

399-
72 ->
415+
"h" ->
400416
5
401417

402-
74 ->
418+
"j" ->
403419
6
404420

405-
75 ->
421+
"k" ->
406422
7
407423

408-
76 ->
424+
"l" ->
409425
8
410426

411-
81 ->
427+
"q" ->
412428
9
413429

414-
87 ->
430+
"w" ->
415431
10
416432

417-
69 ->
433+
"e" ->
418434
11
419435

420-
82 ->
436+
"r" ->
421437
12
422438

423-
84 ->
439+
"t" ->
424440
13
425441

426-
89 ->
442+
"y" ->
427443
14
428444

429-
85 ->
445+
"u" ->
430446
15
431447

432-
73 ->
448+
"i" ->
433449
16
434450

435-
79 ->
451+
"o" ->
436452
17
437453

438-
80 ->
454+
"p" ->
439455
18
440456

441-
90 ->
457+
"z" ->
442458
19
443459

444-
88 ->
460+
"x" ->
445461
20
446462

447-
67 ->
463+
"c" ->
448464
21
449465

450-
86 ->
466+
"v" ->
451467
22
452468

453-
66 ->
469+
"b" ->
454470
23
455471

456-
78 ->
472+
"n" ->
457473
24
458474

459-
77 ->
475+
"m" ->
460476
25
461477

462478
_ ->

0 commit comments

Comments
 (0)