// File: JD297[P]cedit/src/cedit.cpp
// Function: cedit::Cedit::event_write()
void Cedit::event_write()
{
	if( (this->key >= 32 && this->key <= 126) || this->key == 10 || this->key == 9)
	{
		this->contentIt->insert(this->currentIndex, 1, (char)key);
	}

	// Return key
	if(this->key == 10)
	{
		if(this->currentIndex < this->contentIt->length()-1)
		{
			// Insert new line with content after cursor in new line
			this->content.insert(std::next(this->contentIt), this->contentIt->substr(this->currentIndex+1));

			// Shorten the current line until the cursor
			*this->contentIt = this->contentIt->substr(0, this->currentIndex+1);
		}
		else
		{
			// Insert new line empty after current line
			this->content.insert(std::next(this->contentIt), "");
		}

		this->contentIt = std::next(this->contentIt);

		this->currentIndex = 0;
		this->savedIndex = 0;
	}
	else if((this->key >= 32 && this->key <= 126) || this->key == 9)
	{
		this->currentIndex++;
		this->savedIndex = this->currentIndex;
		this->refreshDisplay = false;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xd8(%rbp)
cmpl $0x20, 0x68(%rax)
jl 0x702d
movq -0xd8(%rbp), %rax
cmpl $0x7e, 0x68(%rax)
jle 0x7047
movq -0xd8(%rbp), %rax
cmpl $0xa, 0x68(%rax)
je 0x7047
movq -0xd8(%rbp), %rax
cmpl $0x9, 0x68(%rax)
jne 0x7075
movq -0xd8(%rbp), %rdi
addq $0x18, %rdi
callq 0x92f0
movq %rax, %rdi
movq -0xd8(%rbp), %rax
movq 0x50(%rax), %rsi
movl 0x68(%rax), %eax
movl $0x1, %edx
movsbl %al, %ecx
callq 0x47a0
movq -0xd8(%rbp), %rax
cmpl $0xa, 0x68(%rax)
jne 0x731a
movq -0xd8(%rbp), %rdi
movq 0x50(%rdi), %rax
movq %rax, -0xe0(%rbp)
addq $0x18, %rdi
callq 0x92f0
movq %rax, %rdi
callq 0x4640
movq %rax, %rcx
movq -0xe0(%rbp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x71d7
movq -0xd8(%rbp), %rax
movq %rax, %rcx
addq $0x18, %rcx
movq %rcx, -0xf8(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
movl $0x1, %esi
callq 0x9d90
movq %rax, -0x18(%rbp)
leaq -0x10(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x9dc0
movq -0xf8(%rbp), %rdi
callq 0x92f0
movq %rax, %rsi
movq -0xd8(%rbp), %rax
movq 0x50(%rax), %rdx
incq %rdx
leaq -0x40(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
movq $-0x1, %rcx
callq 0x4430
movq -0xd8(%rbp), %rdi
movq -0xf0(%rbp), %rdx
movq -0x10(%rbp), %rsi
callq 0x9d50
movq %rax, -0xe8(%rbp)
jmp 0x7150
movq -0xe8(%rbp), %rax
movq %rax, -0x58(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x42d0
movq -0xd8(%rbp), %rdi
addq $0x18, %rdi
callq 0x92f0
movq %rax, %rsi
movq -0xd8(%rbp), %rax
movq 0x50(%rax), %rcx
addq $0x1, %rcx
leaq -0x78(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
callq 0x4430
movq -0xd8(%rbp), %rdi
addq $0x18, %rdi
callq 0x9340
movq %rax, %rdi
leaq -0x78(%rbp), %rsi
callq 0x4570
leaq -0x78(%rbp), %rdi
callq 0x42d0
jmp 0x72c9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x42d0
jmp 0x736b
movq -0xd8(%rbp), %rax
movq %rax, %rcx
movq %rcx, -0x108(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rdi
movl $0x1, %esi
callq 0x9d90
movq %rax, -0x88(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x9dc0
leaq -0xb1(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0x4710
movq -0x100(%rbp), %rdx
leaq 0x703d(%rip), %rsi      # 0xe279
leaq -0xb0(%rbp), %rdi
callq 0x90c0
jmp 0x724a
movq -0x108(%rbp), %rdi
movq -0x80(%rbp), %rsi
leaq -0xb0(%rbp), %rdx
callq 0x9d50
movq %rax, -0x110(%rbp)
jmp 0x726a
movq -0x110(%rbp), %rax
movq %rax, -0xc0(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x42d0
leaq -0xb1(%rbp), %rdi
callq 0x44a0
jmp 0x72c9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x72b8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x42d0
leaq -0xb1(%rbp), %rdi
callq 0x44a0
jmp 0x736b
movq -0xd8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rdi
movl $0x1, %esi
callq 0x9d90
movq %rax, %rcx
movq -0xd8(%rbp), %rax
movq %rcx, -0xc8(%rbp)
movq -0xc8(%rbp), %rcx
movq %rcx, 0x18(%rax)
movq $0x0, 0x50(%rax)
movq $0x0, 0x58(%rax)
jmp 0x7362
movq -0xd8(%rbp), %rax
cmpl $0x20, 0x68(%rax)
jl 0x7334
movq -0xd8(%rbp), %rax
cmpl $0x7e, 0x68(%rax)
jle 0x7341
movq -0xd8(%rbp), %rax
cmpl $0x9, 0x68(%rax)
jne 0x7360
movq -0xd8(%rbp), %rax
movq 0x50(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x50(%rax)
movq 0x50(%rax), %rcx
movq %rcx, 0x58(%rax)
movb $0x0, 0x6c(%rax)
jmp 0x7362
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x4700
nopw %cs:(%rax,%rax)