Skip to content
New issue

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

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

Already on GitHub? # to your account

Codemirror and keyboard #551

Open
Tophgirl opened this issue Apr 19, 2017 · 8 comments
Open

Codemirror and keyboard #551

Tophgirl opened this issue Apr 19, 2017 · 8 comments

Comments

@Tophgirl
Copy link

I know this was closed, but looking back at: #306
I want to be able to fix the backspace problem.

Something simple like this works using Codemirror commands:

<script> function backOne() {editor.execCommand("delCharBefore"); } </script>

TestCmd

Unlike with $.extend($.keyboard.keyaction)

But in order for this to work with the keyboard buttons, I need help figuring out how to set the data-action to null, and adding this function to the button.

@Mottie
Copy link
Owner

Mottie commented Apr 19, 2017

Hi @Tophgirl!

I didn't know that the demo(s) stopped working. I'll take a look.

Is the backspace problem you are referring to the problem with the backspace not deleting back to the previous line?

I think we can improve the demos (Codemirror and ACE editor) either way since there is now a beforeInsert callback function that can be used instead of the change callback. It allows a more direct interaction with the editor without worrying about altering any key actions.

@Tophgirl
Copy link
Author

Yes, that was the problem I am talking about.

But I'm unsure what you are suggesting to do with the beforeInsert callback function.

@Tophgirl
Copy link
Author

I think I figured it out, thanks for the help.

@Mottie
Copy link
Owner

Mottie commented Apr 20, 2017

Oh sorry, I was working on a demo on and off. If you have a solution would you please share it?

@Tophgirl
Copy link
Author

Tophgirl commented Apr 20, 2017

all I did was add new keyactions to the jquery.keyboard.js file instead

$keyboard.keyaction = {
		//default functions ....
		cmBksp: function (base) {
			editor.execCommand("delCharBefore");
		},
		cmLineUp: function (base) {
			editor.execCommand("goLineDown");
		},
		cmLineDown: function (base) {
			editor.execCommand("goLineUp");
		}
}

then of course added cmBksp to the layout as another button
I'm sort of new to javascript so don't ask me why this works

@Mottie
Copy link
Owner

Mottie commented Apr 21, 2017

Sorry, I planned on finishing the demo today. I'll try to work on it tomorrow and hopefully provide a nice solution for you.

@Mottie Mottie reopened this Apr 21, 2017
@Mottie
Copy link
Owner

Mottie commented Apr 21, 2017

Ok, I think I got it!

http://jsfiddle.net/Mottie/vyuuas1o/

Let me know if you discover any issues.

$(function() {

  var editor = CodeMirror.fromTextArea(document.getElementById("keyboard"), {
      lineNumbers: true
    }),
    inf = editor.getInputField();

  $(inf).keyboard({
    keyBinding: "mousedown touchstart",
    usePreview: false,
    // lockInput: true,
    autoAccept: true,
    alwaysOpen: true,
    position: {
      of: $(".CodeMirror"),
      my: 'center top',
      at: 'center bottom',
      at2: 'center bottom'
    },
    beforeInsert: function(evnt, keyboard, elem, txt) {
      var position = editor.getCursor();
      if (txt === "\b") {
        editor.execCommand("delCharBefore");
      }
      if (txt === "\b" && position.ch === 0 && position.line !== 0) {
        elem.value = editor.getLine(position.line) || "";
        txt = "";
      }
      return txt;
    }
  });
});

@Tophgirl
Copy link
Author

Interesting, thank you.

@Mottie Mottie mentioned this issue May 5, 2017
28 tasks
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants