Repository: smol-ai/GodMode
File: interface.js (JavaScript)

Code before:
/* ========================================================================== */

// Get the textarea input element for the prompt
const promptEl = document.getElementById('prompt');

// Get the key binding for submitting the prompt from the store
const SuperPromptEnterKey = store.get('SuperPromptEnterKey', false);

promptEl.addEventListener('keydown', function (event) {
	const isCmdOrCtrl = event.metaKey || event.ctrlKey;
	const isEnter = event.key === 'Enter';

	if ((SuperPromptEnterKey && isEnter) || (isCmdOrCtrl && isEnter)) {
		event.preventDefault();
		document.getElementById('btn').click();
	}
});

/* ========================================================================== */
/* Input Event Listener                                                       */
/* ========================================================================== */

let isComposing = false;

promptEl.addEventListener('compositionstart', function() {
  isComposing = true;
});

promptEl.addEventListener('compositionend', function() {
  isComposing = false;
  // The composition has ended, now we can safely handle the input:
  const sanitizedInput = promptEl.value
    .replace(/"/g, '\\"')
    .replace(/\n/g, '\\n');
  enabledProviders.forEach(provider => provider.handleInput(sanitizedInput));
});

promptEl.addEventListener('input', function() {
  // Skip handling the input event if we're in the middle of a composition:
  if (!isComposing) {
    const sanitizedInput = promptEl.value
      .replace(/"/g, '\\"')
      .replace(/\n/g, '\\n');
    enabledProviders.forEach(provider => provider.handleInput(sanitizedInput));
  }
});


/* ========================================================================== */
/* Submit Event Listener                                                      */
/* ========================================================================== */

Review comment (suggestion):
```suggestion
// for Chinese https://github.com/smol-ai/menubar/pull/46
promptEl.addEventListener('compositionstart', function() {
```

Code after:
/* ========================================================================== */

// Get the textarea input element for the prompt
const promptEl = document.getElementById('prompt');

// Get the key binding for submitting the prompt from the store
const SuperPromptEnterKey = store.get('SuperPromptEnterKey', false);

promptEl.addEventListener('keydown', function (event) {
	const isCmdOrCtrl = event.metaKey || event.ctrlKey;
	const isEnter = event.key === 'Enter';

	if ((SuperPromptEnterKey && isEnter) || (isCmdOrCtrl && isEnter)) {
		event.preventDefault();
		document.getElementById('btn').click();
	}
});

/* ========================================================================== */
/* Input Event Listener                                                       */
/* ========================================================================== */

let isComposing = false;

// for Chinese https://github.com/smol-ai/menubar/pull/46
promptEl.addEventListener('compositionstart', function() {
  isComposing = true;
});

promptEl.addEventListener('compositionend', function() {
  isComposing = false;
  // The composition has ended, now we can safely handle the input:
  const sanitizedInput = promptEl.value
    .replace(/"/g, '\\"')
    .replace(/\n/g, '\\n');
  enabledProviders.forEach(provider => provider.handleInput(sanitizedInput));
});

promptEl.addEventListener('input', function() {
  // Skip handling the input event if we're in the middle of a composition:
  if (!isComposing) {
    const sanitizedInput = promptEl.value
      .replace(/"/g, '\\"')
      .replace(/\n/g, '\\n');
    enabledProviders.forEach(provider => provider.handleInput(sanitizedInput));
  }
});


/* ========================================================================== */
/* Submit Event Listener                                                      */