diff --git a/ChangeLog b/ChangeLog
index 7122d44637f9bfc7c8c678af5d0e26c62efdcc91..dcdd2aed7f2ecc661e16a2e8990ae4578471ed81 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,11 @@
 	* files.c (cwd_tab_completion): Remove unneeded assert.
 	* files.c (username_tab_completion, cwd_tab_completion): Rename
 	variable buflen to buf_len, for consistency.
+	* files.c (input_tab): Disable completion of usernames,
+	directories, and filenames if the cursor isn't at the end of the
+	line, as it can lead to odd behavior (e.g. adding a copy of the
+	entire match to the middle of the line instead of just the
+	uncompleted part of the match).
 
 2007-10-05  David Lawrence Ramsey  <pooka109@gmail.com>
 
diff --git a/src/files.c b/src/files.c
index bc6b9e3d539c1fe076322248699a6698654cb453..da0ff9cd13b5f65c43cd4a1f8a95b4a95e57efe0 100644
--- a/src/files.c
+++ b/src/files.c
@@ -2287,7 +2287,7 @@ char **cwd_tab_completion(const char *buf, bool allow_files, size_t
 char *input_tab(char *buf, bool allow_files, size_t *place, bool
 	*lastwastab, void (*refresh_func)(void), bool *list)
 {
-    size_t num_matches = 0;
+    size_t num_matches = 0, buf_len;
     char **matches = NULL;
 
     assert(buf != NULL && place != NULL && *place <= strlen(buf) && lastwastab != NULL && refresh_func != NULL && list != NULL);
@@ -2309,7 +2309,9 @@ char *input_tab(char *buf, bool allow_files, size_t *place, bool
 	matches = cwd_tab_completion(buf, allow_files, &num_matches,
 		*place);
 
-    if (num_matches == 0)
+    buf_len = strlen(buf);
+
+    if (num_matches == 0 || *place != buf_len)
 	beep();
     else {
 	size_t match, common_len = 0;
@@ -2368,8 +2370,6 @@ char *input_tab(char *buf, bool allow_files, size_t *place, bool
 	 * twice in succession with no statusbar changes to see a match
 	 * list. */
 	if (common_len != *place) {
-	    size_t buf_len = strlen(buf);
-
 	    *lastwastab = FALSE;
 	    buf = charealloc(buf, common_len + buf_len - *place + 1);
 	    charmove(buf + common_len, buf + *place, buf_len -